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
{{ message }}
This repository was archived by the owner on Jan 26, 2022. It is now read-only.
During testing async iteration I faced with unexpected result:
constgetPromise=ph=>{returnnewPromise((resolve,reject)=>{ph.resolve=resolve;ph.reject=reject;});};constpromiseHolder={};constpromise=getPromise(promiseHolder);asyncfunction*foo(){yield'#1';varresult=awaitpromise;yieldresult+'#2';yieldresult+'#3';};constf=foo();f.next().then(({ value })=>print('fulfilled #1',value));f.next().then(({ value })=>print('fulfilled #2',value));promiseHolder.resolve('success');f.throw(newError('Some error')).then(({ value })=>print('fulfilled #3',value),error=>print('reject #3',error));f.next().then(({ value })=>print('fulfilled #4',value));
I expect following print:
fulfilled #1 #1
fulfilled #2 success#2
reject #3 Error: Some error
fulfilled #4 undefined
// But I received
fulfilled #1 #1
reject #3 Error: Some error
fulfilled #2 success#2
fulfilled #4 undefined
As I can understand this happened because we do not directly resolve promiseCapabilty but use valueWrapperCapability:
6.4.3.3 AsyncGeneratorResolve
....
6.4.3.3.10. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], onFulfilled, undefined, promiseCapability)
6.4.3.3.11.Perform ! AsyncGeneratorResumeNext(generator).
and in case of throw() we print result earlier because in 6.4.3.4 AsyncGeneratorReject we reject promiseCapabilty without any wrapper.
Could you please suggest is this something wrong in my implementation or it works as expected?