Creates a non-running (paused) timer which will execute a function or specified piece of code when enabled and the timer expires,
this is simular to using scheduleTimeout
but the timer is not enabled (running) and you MUST call refresh
to start the timer.
The timer may be cancelled (cleared) by calling the cancel()
function on the returned ITimerHandler, or
you can "reschedule" and/or "restart" the timer by calling the refresh()
function on the returned ITimerHandler
instance
The function to be executed after the timer expires.
Rest
...args: AThe time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.
Rest
...args: AAdditional arguments which are passed through to the function specified by callback
.
A ITimerHandler instance which can be used to cancel the timeout.
let timeoutCalled = false;
let theTimeout = createTimeout(() => {
// This callback will be called after 100ms as this uses setTimeout()
timeoutCalled = true;
}, 100);
// As the timer is not started you will need to call "refresh" to start the timer
theTimeout.refresh();
// or set enabled to true
theTimeout.enabled = true;
Creates a non-running (paused) timer which will execute a function or specified piece of code when enabled and the timer expires, this is simular to using
scheduleTimeout
but the timer is not enabled (running) and you MUST callrefresh
to start the timer.The timer may be cancelled (cleared) by calling the
cancel()
function on the returned ITimerHandler, or you can "reschedule" and/or "restart" the timer by calling therefresh()
function on the returned ITimerHandler instanceSince
0.7.0
Param: callback
The function to be executed after the timer expires.
Param: timeout
The time, in milliseconds that the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, the next event cycle.
Param: args
Additional arguments which are passed through to the function specified by
callback
.Returns
A ITimerHandler instance which can be used to cancel the timeout.
Example