I have two javascript functions basically on gets return Flights and the other gets departing flights. Currently, the way I have developed it runs one after another. So first it gets all depart flights than starts return flight which is very time-consuming.
Is there a way I can run the functions simultaneously.
Here is sample code:
function onpageLoad()
{
getdepartflights(1,2);
getreturnflights(1,2);
}
// THESE FUNCTIONS FURTHER CAN BE SUMMARIZED AS
function getdepartflights(flightID, flightType) {
PageMethods.getFlights1(flightID, flightType, OnGetMessageSuccessdepart);
}
function getreturnflights(flightID, flightType) {
PageMethods.getFlights2(flightID, flightType, OnGetMessageSuccessreturn);
}
And on OnGetMessageSuccessdepart
and OnGetMessageSuccessreturn
, I simply append the result to Literal so it makes my search result.
So any suggestion on how to improve this so both run the same time as they are independent of each other so should run.
UPDATED
Added this bit of code:
var processor = setInterval(function () {
alert("inside");
searhflightsdepart(i);
clearInterval(processor);
}, 100);
var processor2 = setInterval(function () {
alert("insidereturn");
searhflightsreturn(i);
clearInterval(processor2);
}, 100);
And it looks like it is now running the same time. Is this approach correct? I see two alerts inside and inside return instantly. But again when the first PageMethod is completed than it instantly goes into the second one. So what is stopping it to run async? What to check?