Javascript Promises; the Why and the How.
Josh Miles
102

Nice one!

Couple of things.

If you assign a Promise to a variable, it’s value, once resolved, will always be available on that variable. There is no race condition when attaching .then‘s to the promise chain.

You’ve also missed out a couple of things. .then and .catch are methods on the Promise instance itself. There is also a .done which ends the chain.

resolve and reject are function passed in to the constructor of a Promise, to let it know what values to set it’s internal success and error values to. That’s not quite how they work, but pretty close.

Really nice write up, tho. I’d encourage you to go have a look at the ES Stage 3 proposal for async-await. You can use it now through a babel transform.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.