おい、
v3.0はまだeachSeriesの非同期/待機サポートを提供していませんか? 現在Promiseをサポートしている非同期関数の完全なリストはありますか?
このアップデートで期待されるもの:
async.eachSeries(items, async (item, callback) => {
const itemStats = await someFunc(item);
callback();
});
現在使用中:
async.eachSeries(items, (item, callback) => {
(async () => {
const itemStats = await someFunc(item);
callback();
})();
});
Asyncはasync
関数にコールバックを渡しません。 単にreturn
!
async.eachSeries(items, async (item) => {
const itemStats = await someFunc(item);
});
申し訳ありませんが、私の質問はそれほど良くありませんでした。
callback()がないと、次のエラーを処理できません。
async.eachSeries(items, async (item) => {
const itemStats = await someFunc(item);
if(!itemStats) throw new Error('no stats found');
}, (err) => {
if(err) return res.status(500);
return res.status(200).json({success: true})
});
これはコールバックなしでは機能しませんか?
async
/ await
これを処理する慣用的な方法は、次のようになります。
try {
await async.eachSeries(items, async (item) => {
const itemStats = await someFunc(item);
if(!itemStats) throw new Error('no stats found');
})
} catch (err) {
return res.status(500);
}
return res.status(200).json({success: true})
最も参考になるコメント
async
/await
これを処理する慣用的な方法は、次のようになります。