Quote: The most important characteristic of promises

The most important characteristic of promises is that it normalizes into predictable form how we handle the success or failure of any function call, especially if that call may be asynchronous in nature.

And in that normalization, it leaves our program in a position to control and trust how it will proceed, rather than handing that control (via a callback continuation) off to an untrustable third-party.

https://blog.getify.com/promises-part-2/

Advertisements

Break the promise chains flow

I like the idea of chaining the promises in my code so that it looks nice, pretty nice and easier to read. After several months following this pattern, I have a situation where I need to break the chain promise flow, like stopping the flow. See the below snippet code:

From the above code, I am expecting the code to stop chain and move on to the .catch handler, but is not. I learned the code will continue the flow as I return with no value at line 9.

So, here is the way to break the promise chains, instead of returning with no value, I throw an Error to stop the flow:

Oh, yeah I use Bluebird to working with Promise…