Skip to content

Instantly share code, notes, and snippets.

@aravindmp
Created May 12, 2017 02:11
Show Gist options
  • Save aravindmp/9ad4a0ff903febdb72bdefe0c577b035 to your computer and use it in GitHub Desktop.
Save aravindmp/9ad4a0ff903febdb72bdefe0c577b035 to your computer and use it in GitHub Desktop.
Angularjs sequential chaining promises
var listOfItems = [1, 2, 3, 4, 5];
// Creating an empty initial promise that always resolves itself.
var promise = $q.all([]);
// Iterating list of items.
angular.forEach(listOfItems, function (item) {
promise = promise.then(function () {
return $timeout(function () {
console.log('Item executed: ' + item);
}, 2000);
});
});
promise.finally(function () {
console.log('Chain finished!');
});
@aravindmp
Copy link
Author

Found in the net...Saved it for future use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment