top | item 22366505

(no title)

fjp | 6 years ago

I never wrapped my mind around the Promises API, but I have always async/await is much easier to grasp in any language

discuss

order

pintxo|6 years ago

Maybe because it should have looked like this (personal opinion):

    waitForPromise()
        .then(handleResolve)
        .fail(handleReject)
        .catch(handleException);
But actually looks like this:

    waitForPromise()
        .then(handleResolve, handleReject)
        .catch(handleException);

csnover|6 years ago

waitForPromise().catch(foo) is exactly the same thing as waitForPromise().then(undefined, foo). Your first example is essentially the same as:

    waitForPromise()
        .then(handleResolve)
        .catch(handleReject)
        .catch(handleException);
With the exception that if `handleResolve` also throws then that will be picked up by `handleReject`, whereas in `waitForPromise().then(handleResolve, handleReject).catch(handleException)` it won’t.