收藏
评论

promise.all 在涉及到前后有逻辑关系的异步方法时的处理方式

async function posterAll() {
    const res = await db.collection('goods').get()
 
    const goodsList = res.data
    const task = []
    for (let i = 0; i < goodsList.length; i++) {
        const res1 = cloud.callFunction({
            name: 'utils',
            data: {
                method: 'getWXACode',
                options: {
                    page: 'pages/shop/goods/goods',
                    scene: goodsList[i]._id
                }
            }
        }).then((ok,e)=>{
            cloud.callFunction({
                name: 'admin',
                data: {
                    method: 'goodsUpdate',
                    goodsId: goodsList[i]._id,
                    options: {
                        poster: ok.result.fileID
                    }
                }
            })
        })
 
 
        task.push(res1)
    }
    await Promise.all(task)
}


最后一次编辑于  2018-12-10  (未经腾讯允许,不得转载)
收藏赞 0