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})();