3 ms·
How does it make it difficult?
by coderzach 12y ago
How does it make it difficult?
- lukasm 12y agoI have encounter this problem https://stackoverflow.com/questions/28708238/catching-exceptions-in-async-code-called-synchronously https://stackoverflow.com/questions/28708238/catching-except... Basically, it's hard and prone to bugs.
- TheCoreh 12y agoThe 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.
- sanxiyn 12y agoYou 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-your-function/ http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...
- TheCoreh 12y agoIf 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.