📅  最后修改于: 2022-03-11 15:02:06.410000             🧑  作者: Mango
async function* generateSequence(start, end) {
for (let i = start; i <= end; i++) {
await new Promise(resolve => setTimeout(resolve, 1000));
yield i;
}
}
(async () => {
let generator = generateSequence(1, 5);
for await (let value of generator) {
console.log(value); // 1, then 2, then 3, then 4, then 5 (with delay between)
}
})();