Last active
October 11, 2018 05:02
-
-
Save Dombo/97edd861ff763eacd2a8d4779c6c3e2d to your computer and use it in GitHub Desktop.
Handle a collection of asynchronous actions, serially & blocking, with a consistent API regardless of what happens during execution.
This file contains hidden or 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
# <3 leon | |
const Objects = [{}, {}, {}]; | |
const PromiseBuilders = Objects.map(o => () => promise(o)) | |
const serial = ([first, ..rest], results = []) => | |
first === undefined | |
? Promise.resolve(results) | |
: first() | |
.then(res => serial(rest, results.concat(res))) | |
.catch(err => serial(rest, results.concat(err))) | |
const promise = Promise.resolve('foo') | |
.then(() => { throw 'foo_2' }) | |
.catch(err => { throw err }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment