js async generator

Solutions on MaxInterview for js async generator by the best coders in the world

showing results for - "js async generator"
Ilyas
05 Aug 2020
1async function* generateSequence(start, end) {
2  for (let i = start; i <= end; i++) {
3    await new Promise(resolve => setTimeout(resolve, 1000));
4    yield i;
5  }
6}
7
8(async () => {
9  let generator = generateSequence(1, 5);
10  for await (let value of generator) {
11    console.log(value); // 1, then 2, then 3, then 4, then 5 (with delay between)
12  }
13})();
14