Dev HelpersOpen library
← Back

Consume an async generator

Consume an async generator. A self-contained example using the JavaScript runtime.

Open this example in the interactive library

Source code

async function* stream() {
  yield 1;
  yield 2;
  yield 3;
}
const values = [];
for await (const n of stream()) values.push(n);
console.log(values);

Sample output

[ 1, 2, 3 ]