async/await improvements

James Long longster at
Wed Nov 12 16:18:05 PST 2014

On Wed, Nov 12, 2014 at 7:14 PM, Tab Atkins Jr. <jackalmage at> wrote:
> On Wed, Nov 12, 2014 at 4:07 PM, James Long <longster at> wrote:
>> 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?
> There is currently no way to do so.  If there was, they still wouldn't
> "literally throw", because again, that's impossible - by the time the
> promise rejects, it may be another turn entirely, and the program
> counter is long past the callsite.  The best it can do is be an
> automatically-unhandled error, caught by window.onerror.

You do realize that generators have a `throw` method, and way long
after the generator is yielded you can throw and error from the yield
point and current devtools will correctly pause at that point if you
enable "pause on uncaught exceptions"? A top-level async function
would throw in exactly this same way when an a promise that `await` it
waiting for fails.

This really seems like a huge oversight that there isn't a way to mark
an async function as top-level. When async/await gets here people are
going to want to use that *everywhere*, as they should, and forcing
them to only interact with them as middle-men just so that you can
call `.done()` on an old-style promise chain is weird.

More information about the es-discuss mailing list