Last active
September 26, 2017 13:00
-
-
Save DScheglov/b0d34805d67fc292bc500920bf02e134 to your computer and use it in GitHub Desktop.
Promises
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
const push = results => res => { | |
results.push(res); | |
return results; | |
}; | |
const chainPromises = results => ( | |
(promise, func) => promise.then(func).then(push(results)) | |
); | |
const series = (...promises) => promises.reduce( | |
chainPromises([]), Promise.resolve() | |
); | |
const all = (promises, reduce = series) => reduce(...promises) | |
.then(res => ({ res: res.map(r => r.res) })) | |
.catch(err => ({ err: err.body && err.body.message || err.message || err })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment