Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
随便的撸了一个流式的 promise
// need lodash
const seriesPromise = promises => {
let promisesResults = [];
const tmpPromises = promises.concat(() => {
return Promise.resolve(promisesResults)
});
return _.tail(tmpPromises).reduce((cPromise, nPromise) => {
return cPromise.then(data => {
promisesResults.push(data);
return nPromise();
});
}, _.first(tmpPromises)());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.