promises not executing sequentially javascript
By S.VENGADESHWARAN - April 09, 2017
Ans1:
asyncChain(10, 'FIRST CHAIN').then(function () {
asyncChain(10, 'FIRST CHAIN').then(function () {
return asyncChain(10, 'SECOND CHAIN');
}).then(function(){
return asyncChain(10, 'THIRD CHAIN');
});
Ans2:
var tasks = [fn1, fn2, fn3...];tasks.reduce(function(cur, next) { return cur.then(next); }, RSVP.resolve()).then(function() { //all executed });
Or values:var idsToDelete = [1,2,3]; idsToDelete.reduce(function(cur, next) { return cur.then(function() { return http.post("/delete.php?id=" + next); }); }, RSVP.resolve()).then(function() { //all executed });
0 comments