【发布时间】:2021-10-10 07:53:50
【问题描述】:
我想在async.Series 中使用await 方法
这是我的节点 js 代码
const async = require("async");
async.eachSeries(myArr, function (arr, callback) {
let test = await db.collection('coll').findOne({ _id: arr }); //I couldn't use await here
callback(null, test);
}, function (err) {
console.log("Done");
});
我试过了
async.eachSeries(myArr, async function (arr, callback) {
let test = await db.collection('coll').findOne({ _id: arr }); //It not working here
callback(null, test);
}, function (err) {
console.log("Done");
});
和
async.eachSeries(myArr, async.asyncify(async(function (arr, callback) {
let test = await db.collection('coll').findOne({ _id: arr }); //It not working here
callback(null, test);
})), function (err) {
console.log("Done");
});
如果方法错误,请纠正我,或者让我知道如何在每个异步内部实现等待。
【问题讨论】:
标签: node.js asynchronous async-await async.js