Last active: 2 years ago
Symbol.asyncIterator
class Foo {
#start = 0;
#end = 0;
constructor(end) {
this.#end = end;
}
async *[Symbol.asyncIterator]() {
while (this.#start <= this.#end) {
yield new Promise((resolve) => resolve(this.#start++));
}
}
}
const bar = new Foo(10);
for await (const i of bar) {
console.log(i);
}