Skip to content

Instantly share code, notes, and snippets.

@DScheglov
Last active September 26, 2017 13:00
Show Gist options
  • Save DScheglov/b0d34805d67fc292bc500920bf02e134 to your computer and use it in GitHub Desktop.
Save DScheglov/b0d34805d67fc292bc500920bf02e134 to your computer and use it in GitHub Desktop.
Promises
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