Hey,
v3.0 bringt noch keine Async/Await-Unterstützung für jede Serie? Gibt es eine vollständige Liste, welche asynchronen Funktionen Promise jetzt unterstützen?
Erwartet mit diesem Update:
async.eachSeries(items, async (item, callback) => {
const itemStats = await someFunc(item);
callback();
});
Derzeit im Einsatz:
async.eachSeries(items, (item, callback) => {
(async () => {
const itemStats = await someFunc(item);
callback();
})();
});
Async übergibt keine Rückrufe an async
Funktionen. Einfach return
!
async.eachSeries(items, async (item) => {
const itemStats = await someFunc(item);
});
Sorry, meine Frage war nicht so gut.
Ohne callback() kann ich den Fehler nicht behandeln nach:
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})
});
Ohne Rückruf geht das nicht oder?
Der idiomatische Weg, dies mit async
/ await
zu handhaben, wäre:
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})
Hilfreichster Kommentar
Der idiomatische Weg, dies mit
async
/await
zu handhaben, wäre: