The setTimeout()
function creates and schedules a one-shot timer.
The timer will call func
at or immediately after the specified delay
has elapsed; the timing is not guaranteed to be millisecond-precise. To cancel the callback, call clearTimeout()
, or call Timer.cancel()
on the object returned when the timer is created.
func, delay
func
is a callback function that will be called every time the timer fires.delay
is the time until the timer fires, in milliseconds (different than Timer
functions, but consistent with Javascript).A Timer
object is returned. This can be used to cancel the timer.
Note: the return value is an object, rather than the integer ID returned by Javascript. However, the APIs should be compatible.
> timer = "hello world", 100;
undefined
hello world
hello world
hello world
> timer
undefined
setInterval()
function at MDNTimer()
and Timer.scheduleOnce()
.