Hey,
v3.0 doesn't bring async/await support for eachSeries yet? Is there a full list, which async functions now support Promise?
Expected with this update:
async.eachSeries(items, async (item, callback) => {
const itemStats = await someFunc(item);
callback();
});
Currently in usage:
async.eachSeries(items, (item, callback) => {
(async () => {
const itemStats = await someFunc(item);
callback();
})();
});
Async doesn't pass callbacks to async
functions. Simply return
!
async.eachSeries(items, async (item) => {
const itemStats = await someFunc(item);
});
Sorry, my question wasn't that good.
Without callback() i'm not able to handle the error after:
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})
});
This won't work without callback or?
The idiomatic way to handle this with async
/await
would be:
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})
Most helpful comment
The idiomatic way to handle this with
async
/await
would be: