You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that the generated code for async generators is incorrect.
Search Terms: yield, promise, async, generator.
TypeScript version: master
Node version: 10.0.0
// example.tsfunctionwithDelay(n){returnnewPromise(resolve=>setTimeout(()=>resolve(n),1000));}asyncfunction*makeGenerator(){yield1;yieldwithDelay(2);yield3;yieldwithDelay(4);yield5;}asyncfunctionpull(gen){const{ done, value }=awaitgen.next();console.log('out',value);if(!done){awaitpull(gen);}}pull(makeGenerator());
Expected behavior:
node example.ts # no TS specific stuff in the code
As a workaround, adding await before calls to withDelay works with both (original and generated code):
functionwithDelay(n){returnnewPromise(resolve=>setTimeout(()=>resolve(n),1000));}asyncfunction*makeGenerator(){yield1;yieldawaitwithDelay(2);yield3;yieldawaitwithDelay(4);yield5;}asyncfunctionpull(gen){const{ done, value }=awaitgen.next();console.log('out',value);if(!done){awaitpull(gen);}}pull(makeGenerator());
This is a bug report.
It seems that the generated code for async generators is incorrect.
Search Terms: yield, promise, async, generator.
Expected behavior:
node example.ts # no TS specific stuff in the code
Output:
Same behavior in Chrome 66 and Firefox 58.
Actual behavior:
node built/local/tsc.js --lib 'esnext,esnext.asynciterable' example.ts node example.js
Output:
Playground link
Possible fix:
I was able to fix this by changing
__asyncGenerator
:Would you be ok with such pull request?
The text was updated successfully, but these errors were encountered: