Skip to content

Instantly share code, notes, and snippets.

@krcourville
Created May 5, 2015 01:07
Show Gist options
  • Save krcourville/c22d6a37e0ae526d81ef to your computer and use it in GitHub Desktop.
Save krcourville/c22d6a37e0ae526d81ef to your computer and use it in GitHub Desktop.
Example of sequentially processing an array of promises
function PromiseHelper(){}
PromiseHelper.sequentialProcess = function(promises) {
if(promises.length && promises.length > 0){
return promises.reduce( function( current, acc ) {
return current.then(acc);
});
}else {
return $.when();
}
};
var promises = [1,2,3,4,5].map(function(v){
console.log({v:v});
return $.when(v);
});
PromiseHelper.sequentialProcess(promises).then(function(results){
console.log('done',results);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment