Let async generators directly await an incoming promise
# Isiah Meadows (7 years ago)
Filed tc39/ecma262#1497 to track this. Sounds to me like a spec bug.
Isiah Meadows contact at isiahmeadows.com, www.isiahmeadows.com
Isiah Meadows contact at isiahmeadows.com, www.isiahmeadows.com
Currently the following illustrative syntax is forbidden:
let obj = { async*[Symbol.asyncIterator]() { const res = await yield; // do stuff with res } }Used in this way (simple example):
const ait = obj[Symbol.asyncIterator](); ait.next(); ait.next(p); // p is a PromiseWe cannot directly write
await yield. Is there any particular reason? We have to write:let obj = { async*[Symbol.asyncIterator]() { const res = await (yield); // do stuff with res } }Currently the following illustrative syntax is forbidden: ```js obj = { async*[Symbol.asyncIterator]() { const res = await yield; // do stuff with res } } ``` Used in this way (simple example): ```js const ait = [Symbol.asyncIterator](); ait.next(); ait.next(p); // p is a Promise ``` We cannot directly write `await yield`. Is there any particular reason? We have to write: ```js obj = { async*[Symbol.asyncIterator]() { const p = yield; const res = await p; // do stuff with res } } ``` <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Mail priva di virus. www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190401/14018efb/attachment.html>