If I have two HTTP requests that I need to be called asynchronously, but both must be completed before rendering my view, how can I ensure that these two separate calls are done in order to trigger a specific function? Calls 3 and 4 can continue running in the background without waiting for them to finish.
Here is an example code snippet:
var call1_done = false;
var call2_done = false;
var call3_done = false;
var call4_done = false;
API.get_client().then(function(){
call1_done = true;
});
API.get_all_clients().then(function(){
call2_done = true;
});
// Ignore calls 3 and 4 as they can continue running in the background
if (call1_done && call2_done)
{
render_the_page();
}