Skip to content

Instantly share code, notes, and snippets.

@malectro
Created April 8, 2015 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malectro/455607d0022e57faca09 to your computer and use it in GitHub Desktop.
Save malectro/455607d0022e57faca09 to your computer and use it in GitHub Desktop.
Executes an array of promises in sequence. Useful when all promises access the same lock and could possibly time out if run in parallel (as in a database migration).
var forEachPromise = function (array, callback) {
var i = 0;
function iterate() {
if (i < array.length) {
callback(arrray[i]).then(function () {
i++;
iterate();
});
}
}
iterate();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment