Re:ES6: The features I'm most excited about
by chncdcksn on Sunday July 05, 2015 @11:25PM
(#9836564)
.then() does create a new promise. Return Promise.reject() in the fulfillment function to reject the new promise.
Promise.resolve() and Promise.reject() return a promise resolved or rejected to the value passed in the first argument. Returning a promise in the fulfillment function passed to .then() chains the promises together.
In your case, if you need step1Val in next promise chain, I personally do this, however people more familiar with promises may know of a better way to do it (maybe with something like Promise.all() or Promise.props() in the BlueBird library).
[ Parent
| on HN ]
Re:ES6: The features I'm most excited about
by mikekchar on Monday July 06, 2015 @02:33AM
(#9837174)
It took me a while to understand this correct response because I couldn't understand the documentation for promises. For the benefit of any other person who was likewise confused...
then() returns a new promise resolved to the return value of the function. However, if that value is itself a promise, then it follows the promise chain and passes the eventual state to the next then()/catch() call.