David wyatt
Posts: 0
Joined: Mon Sep 15, 2014 7:12 pm

Delay between functions

Hi,

On a button click i have a list of javascripts running in order. What i need is for there to be a delay between 2 of them. ive tried adding a run javascript with following text

window.setTimeout(Functionwait, 1000);
function functionwait() {
}
but is just stops the list commands at this point and doesnt execute any others after.

thanks Image

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Delay between functions

Hello,

You can write all code on one click event, then time out should work as expected.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Delay between functions

Hello!

You invoke all handlers on the same event. It would be better to join them in one code and invoke with delay as you specified using setTimeout for each function. Or if you want to guarantee functions execution sequence, use callbacks:
prefunction foo(params, callback){
// do stuff with params

// move on to next step
callback(params)
}

function bar(params, callback){
// do stuff with params

// move on to next step
callback(params)
}/pre

David wyatt
Posts: 0
Joined: Mon Sep 15, 2014 7:12 pm

Delay between functions

Hi,

thanks Maryna, works great now.

thank you

umama fakher
Posts: 0
Joined: Fri May 22, 2015 4:26 pm

Delay between functions

only first function is executing second is not executing ?

umama fakher
Posts: 0
Joined: Fri May 22, 2015 4:26 pm

Delay between functions

I am using your code like this. I want the database service executed than the mailto window open and then it navigates to start page alerting the success.
Am I using your code correctly?
pre
function foo(params, callback){
databaseService.execute({});
window.open('mailto:someone@example.com?subject=any&body=any');

callback(params);
}
function bar(params,callback){
window.open('mailto:someone@example.com?subject=any&body=any');
Apperyio.navigateTo('StartPage', {});

callback(params);
}
/pre

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Delay between functions

Hi Umana,

You don't need such technique.

So the solution is:

1 On first service "Success" event add "Run javascript" event handler.

2 Populate it with following js code:

pre

Code: Select all

 window.open('mailto:someone@example.com?subject=any&body=any');  

 Apperyio.navigateTo('StartPage', {}); 

/pre

Regards.

umama fakher
Posts: 0
Joined: Fri May 22, 2015 4:26 pm

Delay between functions

Thankyou so much. This is working. Cheers Appery.io team :) !!

Return to “Issues”