美文网首页WEB开发
node中,防止跳过异步操作的方法

node中,防止跳过异步操作的方法

作者: 情有千千节 | 来源:发表于2019-11-01 22:11 被阅读0次
 if (userid !== -1) {
    let hasUser = await db.selectUser(userid)
    if (hasUser.length === 0) {
      // 证明查无此人
      await list.map(e => {
        e.isAgree = false
        e.image = `${config.image_url}${e.image}`
        return e
      })
    } else {
      // 这里使用Promise.all 等待 执行完成才进行下一步
      
      await Promise.all(list.map(async e => {
        let agreeType =  await isAgree.select({
            imgid: e.imageid,
            activeid: e.activeid,
            userid: userid
          })
          agreeType[0]==undefined ? e.isAgree=false : e.isAgree= true
          e.image = `${config.image_url}${e.image}`
          return e
      }))
    }
  }

相关文章

网友评论

    本文标题:node中,防止跳过异步操作的方法

    本文链接:https://www.haomeiwen.com/subject/vdboectx.html