The following shows timer module APIs available for each platform.
Linux (Ubuntu) |
Raspbian (Raspberry Pi) |
NuttX (STM32F4-Discovery) |
TizenRT (Artik053) |
|
---|---|---|---|---|
setTimeout | O | O | O | O |
clearTimeout | O | O | O | O |
setInterval | O | O | O | O |
clearInterval | O | O | O | O |
The timer
module exposes a global API for scheduling functions to be called at some future period of time. Because the timer functions are globals, there is no need to call require('timers') to use the API.
callback
{Function} The function to call when the timer elapses....args
{any}
delay
{number} The number of milliseconds to wait before calling thecallback
....args
{any} - Optional arguments to pass when thecallback
is called.- Returns: {Timeout}
Schedules execution of a one-time callback
after delay
milliseconds. Returns a Timeout
for use with clearTimeout()
. If callback
is not a function, a TypeError
will be thrown.
Example
var timeout = setTimeout(function() {
// Do something which will be executed after one second.
}, 1000);
timeout
{Timeout} A Timeout object returned bysetTimeout()
.
Cancels a Timeout
object created by setTimeout()
.
Example
var timeout = setTimeout(function() { }, 1000);
...
clearTimeout(timeout);
callback
{Function} The function to call when the timer elapses....args
{any}
delay
{number} The number of milliseconds to wait before calling thecallback
....args
{any} - Optional arguments to pass when thecallback
is called.- Returns: {Timeout}
Schedules repeated execution of callback
every delay
milliseconds. Returns a Timeout
object for use with clearInterval()
. If callback
is not a function, a TypeError
will be thrown.
Example
var timeout = setInterval(function() {
// Do something which will be executed repeatadly one time per second.
}, 1000);
timeout
{Timeout} A Timeout object as returned bysetInterval()
.
Cancels a Timeout
object created by setInterval()
.
Example
var timeout = setInterval(function() { }, 1000);
...
clearInterval(timeout);
This object is created internally and is returned from setTimeout()
and setInterval()
.
When called, requests that the IoT.js event loop should not exit as long as the Timeout
is active.
When called, the active Timeout
object will not force the IoT.js event loop to remain active. If there are no other scheduled activites, the process may exit, the process may exit before the Timeout
object's callback is invoked.