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.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…