How to use "Schedule Once"

bonsai
Mega Sage

※Paris version

I'm aiming for script concurrency using "Schedule Once".

I understand how to use it as follows,
I don't understand how it works.

function script(argument){
    //ScheduleJob
    gs.info(argument);
} 
var argument ="Test OK"
var sched = new ScheduleOnce();
sched.script = '('+script+')("'+argument+'");';
sched.schedule();

 

I wondered if "script" should be a string in the "'(' + script +')" part, but why specify the function name?

I'm learning a script so please let me know.

1 ACCEPTED SOLUTION

Re-read the original question.

No, "script" should not be a string. It's a function.

For example, following code will call the function named "script" immediately.

function script(argument){
    //ScheduleJob
    gs.info(argument);
}
var argument ="Test OK"
(script)(argument);

As such, in sched.script, it's necessary to pass the function named "script" (i.e. the content of the function) and not the entire definition of the function including "function script(argument)) {".

sched.script = '('+script+')("'+argument+'");';

That is, 

sched.script = 'gs.info("test ok");';

and not this,

sched.script = 'function script(){gs.info("test ok");}';

View solution in original post

5 REPLIES 5

palanikumar
Giga Sage

Hi,

In your example "'(' + script +')" refers the function named script defined in first line. You should add all your code inside this function. If you change the name of this function then the same name to be used in this line you mentioned

Thank you,

Palani

Thank you,
Palani