T.J. Crowder (2017-04-14T11:17:57.000Z)
tj.crowder at farsightsoftware.com (2017-04-14T11:28:19.032Z)
> ...that'd break when using multiple returns with different types. Well, not necessarily. It may have been possible to make the promise the async function returns be of the same type as the first promise it encounters during the synchronous part of its execution (remember that execution is synchronous until the first `await` or `return`). E.g.: ```js async function foo() { console.log("This is the synchronous bit"); if (someCondition) { await a(); } else { await b(); } return await c(); } ``` Assume `a` and `b` return different types of promises. *Conceptually* it would have been possible to make `foo` return a promise of the same type as the one returned by `a` if `someCondition` were true or the same type as `b`'s promise if `someCondition` were false. E.g., as though it were like this: ```js function foo() { console.log("This is the synchronous bit"); let p; if (someCondition) { p = a(); } else { p = b(); } return p.then(_ => c()); } ``` That's just not how it's defined in the proposal and upcoming 2017 spec. I don't know if there's some implementational reason that wasn't done, or a philosophical reason, or what. It would certainly be more complex to implement and understand than what's been specified; I'm not surprised simplicity won out. Re: > `var k = (async function() {await window.setTimeout(1000); return randomPromiseSubtype})();` (Missing a callback there.) In that situation, in our alternate universe where async functions did what medikoo wants, the function would return a promise created by `NewPromiseCapability(%Promise%)`, since the function had to generate its own promise due to awaiting a synchronous function. E.g., the first promise it encountered in its synchronous code would be (effectively) `Promise.resolve(window.setTimeout(callback, 1000))`. I'm not trying to suggest I think it would have been better. I like simplicity. But I do see what medikoo is getting at, and conceptually I'm not immediately seeing why it *couldn't* have been done that way instead. -- T.J. Crowder