Hacker News new | ask | show | jobs
by coderzach 4128 days ago
How does it make it difficult?
2 comments

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...

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.

I have encounter this problem https://stackoverflow.com/questions/28708238/catching-except...

Basically, it's hard and prone to bugs.

The implementation in JS seems to be simpler and consequently less error prone than the one in C#. Calling an async function just returns a Promise. The await operator just yields to the event loop until a given Promise is fullfilled. Exceptions are handled "normally" inside the async function with try/catch, outside they're handled with a callback, like in existing code that uses promises.