Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run promises in series with an initial value
// promises are wrapped in a function - known as "promise-providers"
const providers = [
function(v){
return Promise.resolve(v+1);
},
function(v){
return Promise.resolve(v+2);
},
function(v){
return Promise.resolve(v+3);
}
];
const inSeries = function(providers, initialVal){
if(providers.length < 1){
return Promise.resolve(null);
}
return providers.reduce((a,b) => a.then(b), providers.shift()(initialVal));
};
inSeries(providers, 1).then(v => {
console.log(v);
});
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.