Skip to content

Instantly share code, notes, and snippets.

@jondejong
Created February 10, 2016 22:49
Show Gist options
  • Save jondejong/0b499a20cfb17176afb4 to your computer and use it in GitHub Desktop.
Save jondejong/0b499a20cfb17176afb4 to your computer and use it in GitHub Desktop.
A simple, if ugly, approach to promise chaining
var things = [
//...Array of things to process...
];
var methodThatReturnsPromise() = function {
// Must be executed on all the things
// In order
// return a promise
};
var i = 0;
var whenDone = function () {
//We're done now, move on...
};
var proccessThing = function (thing) {
return methodThatReturnsPromise(thing).then(function () {
i++;
if (i < thing.length) {
proccessThing(things[i]);
} else {
whenDone();
}
});
};
proccessThing(things[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment