Skip to content

Instantly share code, notes, and snippets.

@scabbiaza
Created October 17, 2016 17:06
Show Gist options
  • Save scabbiaza/720e20024c90416e38d6d7a7b31c6a5e to your computer and use it in GitHub Desktop.
Save scabbiaza/720e20024c90416e38d6d7a7b31c6a5e to your computer and use it in GitHub Desktop.
// Sequence of promises
let promise = Q();
let result = [];
R.forEach(page => {
promise = promise.then(r => {
result = R.merge(r, result);
return fetch(page);
});
}, R.range(0, pages));
return promise.then(() => {
console.log('result: ', result);
});
// Alternative way
var promise = Q();
R.reduce((memo, page) => {
return memo.then(r1 => {
return fetch(page)
.then((r2) => r1.concat(r2))
});
}, Q.resolve([]), R.range(0, pages));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment