Closed gamevnlc closed 3 years ago
You don't need Async for this.
await Promise.all(listOfPromises)
or
Promise.all(listOfPromises).then((results) => {})
@aearly yes I knew it, just wondering is it possible to use promise with Async.Parallel
Passing it a list of async
functions will work, but you're still better off using Promise.all
.
Darn, I was hoping to do this with parallel()
since it is a bit nicer than Promise.all()
because it accepts an object as well as an array.
For example, I have something like this (with many more functions each with more args in reality):
async function getNames(a, b, c) { ... }
async function getPages(a, b, c) { ... }
async function buildCombined(with, some, args) {
const combined = await async.parallel({
names: async () => getNames(with, some, args),
pages: async () => getPages(with, some, args),
});
return combined;
}
It would be nice to remove the async () =>
and have parallel
handle Promise
values directly.
You should already be able to do that: https://github.com/caolan/async/blob/master/test/es2017/asyncFunctions.js#L473-L482
Either I did not explain clearly, or I do not understand the code you referenced in your answer. If I remove the async
wrapper function like below, I don't think it works?
async function getNames(a, b, c) { ... }
async function getPages(a, b, c) { ... }
async function buildCombined(with, some, args) {
const combined = await async.parallel({
names: getNames(with, some, args),
pages: getPages(with, some, args),
});
return combined;
}
Hi everyone I want to pass a list of promises to parallel, but it shows the error
Error: expected a function
. Is there any way to do it. Thanks