0

I am facing issue in my project. I have to send 5 calls to database. after Sequence: 1 -> 2-> 3,4,5

i am using shared app.factory service for call. i am unable to do so. i am using angularjs. if i do async:false, all calls will be async and this will take time. if i make it true, my 1->2 call repsond late, and 3,4,5 calls respond very early.

app.factory have shared success call for proc1, proc2,proc3,proc4,and proc5.

i want to execute 1->2 calls and then 3,4,5 parallel.

thanks

Faseeh Haris
  • 669
  • 1
  • 11
  • 29
  • I think this question encapsulates what you want to do http://stackoverflow.com/questions/32546248/chain-angular-http-calls-properly. – Ronald91 Dec 08 '16 at 19:08

1 Answers1

1

Your calls to the database need to return promises, which can then be chained together.

var result = service.call1(args)
.then(function(){return service.call2;})
.then(function($q){
    var promises = [
        service.call3,
        service.call4,
        service.call5
    ];
    return $q.all(promises);
});

Without seeing any of your code structure this is about as specific as I can get, but it should be enough to show you what to do.

MBielski
  • 6,628
  • 3
  • 32
  • 43