Skip to content

Instantly share code, notes, and snippets.

@Aankhen
Last active April 18, 2018 20:10
Show Gist options
  • Save Aankhen/a8f7ab7579438cfb58903e269c0631ea to your computer and use it in GitHub Desktop.
Save Aankhen/a8f7ab7579438cfb58903e269c0631ea to your computer and use it in GitHub Desktop.
Unable to use async generators with ts-node (+ generated index.js)
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
"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");
});
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");
});
{
"compilerOptions": {
"target": "esnext",
"strict": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment