Skip to content

Instantly share code, notes, and snippets.

@petvas
Last active February 25, 2016 22:29
Show Gist options
  • Save petvas/329fca582e31921d3860 to your computer and use it in GitHub Desktop.
Save petvas/329fca582e31921d3860 to your computer and use it in GitHub Desktop.
Promises Chaining (Sequences)
/**
* 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