Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NB: This is made using angular's $q, but this applies to anything else
- promiseChain = function(array, passedPromise) {
- let chain = $q((resolve, reject) => resolve());
- for (let elem of array)
- chain = chain.then(_ => passedPromise(elem));
- return chain;
- };
- // This returns a timeout wrapped in a promise
- let testFn = function(s) {
- return $timeout(function() {
- console.log(s);
- }, 500);
- };
- let promise = makePromiseChain([1,2,3,4,5,6,7,8,9], testFn);
- promise.then(_ => console.log('finished'));
- $q((resolve, reject) => resolve())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement