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());
Activity
j-oliveras commentedon May 3, 2018
As a workaround, adding
awaitbefore calls towithDelayworks with both (original and generated code):nmain commentedon May 3, 2018
Is this related to #21115?
falsandtru commentedon May 4, 2018
Duplicate of #23731
mhegazy commentedon May 9, 2018
thanks Artem Tyurin (@agentcooper)!