Last active
February 25, 2016 22:29
-
-
Save petvas/329fca582e31921d3860 to your computer and use it in GitHub Desktop.
Promises Chaining (Sequences)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Promises Chaining | |
*/ | |
(function () { | |
var promises = [ | |
() => Promise.resolve('1st'), | |
() => Promise.resolve('2nd'), | |
() => Promise.resolve('...'), | |
() => Promise.resolve('n'), | |
]; | |
/** | |
* Chaining promises, start with empty promise | |
*/ | |
var chainedPromise = promises.reduce((prev, f) => prev.then(f), Promise.resolve('Start')); | |
/** | |
* Catch Fails | |
*/ | |
chainedPromise.catch(console.log.bind(console)); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment