How to call services in correct order? Promises in Apperyio app.

Problem:

You have page with at least 2 Apperyio services. You may want to call 3rd service only after both services finished its execution.

Calling services one by one

and calling service #3 on success handler of restservice2 will not work. You don’t know how long it will take for restservice2 to get response from server.
Solution:

Ask any front-end developer “what should I use when 2 or more processes are asynchronous ?” you will hear “Use promises”. Promises are essential to any asynchronous events.

I have 2 different approaches:

  1. calling Apperyio Database collections with jQuery.ajax method
  2. calling Apperyio services

 

Calling with jQuery.ajax method

 

Calling Apperyio services  

1.Lets create a button on page with custom javascript on Click event:

 

2.Add “Run Javascript” event on Success of your service with code below:

3. Same code, but with service2_promise instead of service1_promise add to 2nd service

4. Add same event for Error event handler for both of your services

This is minimum what should do to call 3rd service only after both restservice1 and restservice2 will finish it’s execution.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *