Created
May 5, 2015 01:07
-
-
Save krcourville/c22d6a37e0ae526d81ef to your computer and use it in GitHub Desktop.
Example of sequentially processing an array of promises
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
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