import com.ibm.egl.rui.widgets.Button; import egl.javascript.Job; handler MyHandler type RUIhandler { initialUI = [stopButton], onConstructionFunction = initialization } stopButton Button{text="Stop!", onclick ::= pleaseStop}; doThis Job{runFunction = myRunFunction}; function initialization() doThis.repeat(1000); end function myRunFunction() sysLib.writeStdOut(currentTime()); end function pleaseStop(e event in) doThis.cancel(); end end
import egl.javascript.Job;
You cannot add that statement with the Ctrl-Shift-O mechanism that is available for Widget types.
The timer is reset each time the run function starts. The rule for each invocation of the run function, including the first, is that the invocation occurs, at earliest, when the timer elapses or when the current function ends, whichever happens last.
The invocation of a run function never interrupts the execution of another function. For example, between the time when a job is scheduled and the time when the invocation of the run function is possible, the user might click a button to cause scheduling of an event handler. In that case, the invocation of the job function waits at least until the event handler invokes its own subordinate functions, if any, and ends.
You can create multiple variables of type JOB and in this way schedule multiple jobs and even invoke the same run function. In all cases, only one function can run at a given time, and it runs to completion.
If you use the same variable to reschedule a job, the previous use of that variable is canceled.