{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/proposal-async-iteration/issues/93","repository_url":"https://api.github.com/repos/tc39/proposal-async-iteration","labels_url":"https://api.github.com/repos/tc39/proposal-async-iteration/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/tc39/proposal-async-iteration/issues/93/comments","events_url":"https://api.github.com/repos/tc39/proposal-async-iteration/issues/93/events","html_url":"https://github.com/tc39/proposal-async-iteration/issues/93","id":213464066,"number":93,"title":"Clarification of execution of next() and throw() with await ","user":{"login":"gskachkov","id":4946944,"avatar_url":"https://avatars2.githubusercontent.com/u/4946944?v=3","gravatar_id":"","url":"https://api.github.com/users/gskachkov","html_url":"https://github.com/gskachkov","followers_url":"https://api.github.com/users/gskachkov/followers","following_url":"https://api.github.com/users/gskachkov/following{/other_user}","gists_url":"https://api.github.com/users/gskachkov/gists{/gist_id}","starred_url":"https://api.github.com/users/gskachkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gskachkov/subscriptions","organizations_url":"https://api.github.com/users/gskachkov/orgs","repos_url":"https://api.github.com/users/gskachkov/repos","events_url":"https://api.github.com/users/gskachkov/events{/privacy}","received_events_url":"https://api.github.com/users/gskachkov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":39,"created_at":"2017-03-10T22:03:47Z","updated_at":"2017-03-17T21:37:24Z","closed_at":null,"body":" During testing async iteration I faced with unexpected  result:\r\n\r\n```javascript\r\nconst getPromise = ph => {\r\n    return new Promise((resolve, reject) => {\r\n        ph.resolve = resolve;\r\n        ph.reject = reject;\r\n    });\r\n};\r\nconst promiseHolder = {};\r\nconst promise = getPromise(promiseHolder);\r\n\r\nasync function *foo() {\r\n    yield '#1';\r\n    var result = await promise;\r\n    yield result + '#2';\r\n    yield result + '#3';\r\n};\r\n\r\nconst f = foo();\r\n\r\nf.next().then(({ value })=> print('fulfilled #1', value));\r\nf.next().then(({ value })=> print('fulfilled #2', value));\r\n\r\npromiseHolder.resolve('success');\r\n\r\nf.throw(new Error('Some error')).then(({ value })=> print('fulfilled #3', value), error=> print('reject #3', error));\r\nf.next().then(({ value })=> print('fulfilled #4', value));\r\n``` \r\nI expect following print:\r\n```\r\nfulfilled #1 #1\r\nfulfilled #2 success#2\r\nreject #3 Error: Some error\r\nfulfilled #4 undefined\r\n// But I received \r\nfulfilled #1 #1\r\nreject #3 Error: Some error\r\nfulfilled #2 success#2\r\nfulfilled #4 undefined\r\n```\r\nAs I can understand this happened because we do not directly resolve _promiseCapabilty_ but use _valueWrapperCapability_:\r\n6.4.3.3 AsyncGeneratorResolve\r\n....\r\n6.4.3.3.10. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], onFulfilled, undefined, promiseCapability)\r\n6.4.3.3.11.Perform ! AsyncGeneratorResumeNext(generator).\r\nand in case  of throw() we print result earlier because in _6.4.3.4 AsyncGeneratorReject_ we reject _promiseCapabilty_ without any wrapper.\r\n\r\nCould you please suggest is this something wrong in my implementation or it works as expected?\r\n\r\nBest regards,\r\nOleksandr"},"comment":{"url":"https://api.github.com/repos/tc39/proposal-async-iteration/issues/comments/287477627","html_url":"https://github.com/tc39/proposal-async-iteration/issues/93#issuecomment-287477627","issue_url":"https://api.github.com/repos/tc39/proposal-async-iteration/issues/93","id":287477627,"user":{"login":"erights","id":273868,"avatar_url":"https://avatars0.githubusercontent.com/u/273868?v=3","gravatar_id":"","url":"https://api.github.com/users/erights","html_url":"https://github.com/erights","followers_url":"https://api.github.com/users/erights/followers","following_url":"https://api.github.com/users/erights/following{/other_user}","gists_url":"https://api.github.com/users/erights/gists{/gist_id}","starred_url":"https://api.github.com/users/erights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erights/subscriptions","organizations_url":"https://api.github.com/users/erights/orgs","repos_url":"https://api.github.com/users/erights/repos","events_url":"https://api.github.com/users/erights/events{/privacy}","received_events_url":"https://api.github.com/users/erights/received_events","type":"User","site_admin":false},"created_at":"2017-03-17T21:37:24Z","updated_at":"2017-03-17T21:37:24Z","body":"> Can you explain why that would be horrible? \r\n\r\nI doubt I have anything new to say on the matter. FWIW, I do understand the rationale for the opposite position. If you'll be at tc39, let's try to find time to discuss f2f."}}
{"actor":{"display_login":"erights"}}