1

In both of at the time of execution of an asynchronic operation only.


  • But how the $q handle for this is a Sequential call or Parallel call on runtime?
  • and let me brief explanation about the Difference between Sequential and Parallel executing in angular $q
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234

2 Answers2

2

Parallel Execution is something in which it doesn't wait for the previous process to be done,and Sequential is something in which process are executed one after another.

$q service is used for asynchronous call (parallel execution | promise handling),by default it does parallel execution,it does not have support for sequential execution. If you want a sequential execution you have to handle it manually, wheich means after getting response from one call you make another call.

var promise;
promise.then(fun(){
   var promise;
   promise.then(fun(){
   })
})
balajivaishnav
  • 2,795
  • 4
  • 23
  • 38
sonu singhal
  • 211
  • 1
  • 6
0

To execute promises in parallel:

var promise1 = promiseAPI(params1);
var promise2 = promiseAPI(params2);

var promise1and2 = $q.all([promise1, promise2]);

To execute promises sequentually, return the next promise to the first promise success handler:

var promise1 = promiseAPI(params1);

var promise1then2 = promise1.then(function() {
    var promise2 = promiseAPI(params2);
    //return to chain
    return promise2;
});

Because calling the .then method of a promise returns a new derived promise, it is easily possible to create a chain of promises. It is possible to create chains of any length and since a promise can be resolved with another promise (which will defer its resolution further), it is possible to pause/defer resolution of the promises at any point in the chain.

-- AngularJS $q Service API Reference -- Chaining Promises.

georgeawg
  • 48,608
  • 13
  • 72
  • 95