async/await improvements

James Long longster at
Wed Nov 12 16:07:43 PST 2014

On Wed, Nov 12, 2014 at 6:58 PM, Tab Atkins Jr. <jackalmage at> wrote:
> On Wed, Nov 12, 2014 at 3:53 PM, James Long <longster at> wrote:
>> On Wed, Nov 12, 2014 at 6:46 PM, Tab Atkins Jr. <jackalmage at> wrote:
>>> On Wed, Nov 12, 2014 at 3:36 PM, James Long <longster at> wrote:
>>>> `await` is *always* inside an `async` function so there's always a
>>>> promise created for that function which is waiting for it to be done
>>>> executing. That's the one I'm talking about.
>>> Okay.  That doesn't change my response.  The outer async function also
>>> returns a promise, and doesn't run syncly with *its* caller, so it's
>>> again physically impossible for it to throw an error at its callsite
>>> (again, unless *its* caller has opted into asynchrony and used
>>> `await`).
>> Yeah, I'm only talking about call sites that used `await`. Although,
>> mainly the question is when an error happens inside an `async`
>> function, whether it throws at that point or passes it onto the
>> returning promise. You're definitely going to view that differently
>> whether you embrace promises or not.
> If both the outer and inner callsites used "await", and the innermost
> callee returned a rejected promise, then the inner "await" will throw,
> which causes its containing function to reject its promise, which
> causes the outer "await" to throw (which then causes the outer
> function to reject its promise).

Right, I'm saying that the "throw" at the inner `await` would be a an
actual uncaught exception unless the async function has been
explicitly marked as something that should forward errors (i.e. a
function that returns a promise). I prefer marking things to propagate
rather then marking the end of the chain (.done()). That's the big
difference that opposes the promise-style behavior, and is why it's
probably hard for you to understand what I mean.

(It's the difference between C# `async static void AsyncVersion() {}`
and `async static Task AsyncVersion() {}`).

Maybe this would be resolved if you could answer this: how do you mark
an async function to be a top-level one? I don't see anywhere that
says "I don't return a promise, I want errors inside of me to
literally throw. I am an all-powerful top-level consumer of async
stuff"). Seems like that would need extra syntax?

More information about the es-discuss mailing list