Last active
April 18, 2018 20:10
-
-
Save Aankhen/a8f7ab7579438cfb58903e269c0631ea to your computer and use it in GitHub Desktop.
Unable to use async generators with ts-node (+ generated index.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@ubuntu-xenial:/async-generators-test$ npm i -S typescript ts-node | |
...omitted... | |
vagrant@ubuntu-xenial:/async-generators-test$ node --version | |
v9.11.1 | |
vagrant@ubuntu-xenial:/async-generators-test$ npm ls ts-node | |
/async-generators-test | |
└── ts-node@6.0.0 | |
vagrant@ubuntu-xenial:/async-generators-test$ npx ts-node --harmony_async_iteration index.ts | |
> .exit | |
vagrant@ubuntu-xenial:/async-generators-test$ npx tsc -p tsconfig.json | |
vagrant@ubuntu-xenial:/async-generators-test$ node --harmony_async_iteration index.js | |
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
async function* numbers() { | |
for (let i = 0; i < 10; i++) | |
yield i; | |
} | |
new Promise(async (resolve, reject) => { | |
for await (const i of numbers()) { | |
console.log(i); | |
} | |
}).then(() => { | |
console.log("Done"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function* numbers() { | |
for (let i = 0; i < 10; i++) | |
yield i; | |
} | |
new Promise(async (resolve, reject) => { | |
for await (const i of numbers()) { | |
console.log(i); | |
} | |
}).then(() => { | |
console.log("Done"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "esnext", | |
"strict": true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment