Hacker News new | ask | show | jobs
by sanxiyn 4128 days ago
You can only call async functions inside async functions.

See also What color is your function? http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...

1 comments

If that was the case then async functions would be useless, since the global scope is not an async function. You can call async functions from regular functions, they will just return a promise. You can then use normal promise handing behavior (passing a callback function, which is how you'd currently handle async anyway).

In real-world scenarios though, most of the time you'll be reacting to events, and not calling async code from sync code.

Edit: To clarify I'm talking about the ES7 async/await feature.