Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I understand there are two sides/groups here: 1) Those who think errors are important to control flow, and 2) Those who think errors are exceptions to control flow. If you are in group 2 both Promises and async/await will give you neat and simple code. But if you are in group 1 Promises and async/await will be really complicated and ugly because each await will be inside a try/catch.

Because I'm in group 1, I try to avoid Promises (and thus async/await) in JS because the promise will capture all future errors, and if you forget to add a .catch, that error will never surface. Promises make asynchronous code more complicated. Async/await however get rid of a lot of the complicated syntax, so when I do not care about errors (eg. errors are exceptions) I use async/await because of easier control flow.



Those who think of errors as exceptions can further be divided into group 2a) Those who prefer Promises syntax. And group 2b) Those who prefer async/await syntax.

Also don't forget about co-routines:

    co(function* () {
        var user = yield getUser();
        var comments = yield getComments(user);
    });
Just replace "co(" with async, and yield with await, and you'll have async/await.


Errors are an important part of the control flow, if you are doing UI programming, which is what Javascript is made for.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: