Created
October 17, 2016 17:06
-
-
Save scabbiaza/720e20024c90416e38d6d7a7b31c6a5e to your computer and use it in GitHub Desktop.
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
// 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