Created
May 12, 2017 02:11
-
-
Save aravindmp/9ad4a0ff903febdb72bdefe0c577b035 to your computer and use it in GitHub Desktop.
Angularjs sequential chaining promises
This file contains hidden or 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
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!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found in the net...Saved it for future use.