Given I have an async generator:
async function* generateItems() {
// ...
}
What's the simplest way to iterate all the results into an array? I've tried the following:
// This does not work
const allItems = Array.from(generateItems());
// This works but is verbose
const allItems = [];
for await (const item of generateItems()) {
allItems.push(item);
}
(I know this is potentially bad practice in a Production app, but it's handy for prototyping.)
await
ed individually in order to get access to the next PromiseallItems = await generateItems().toArray()
is currently proposedArray.asyncFrom
proposal that mentions this post.