, , .
example.js
async function* async_generator() {
for (let i = 0; i < 10; i++) {
yield await new Promise(r => setTimeout(_ => r("hello world"), 100))
};
}
async function main(){
for await (let item of async_generator()){
console.log(item);
}
}
main().catch(console.log);
( node v8.5.0)
node --harmony-async-iteration example.js
, 3, , , , typescript babel.
update:
node 9, . --harmony.