ShadowNode

Use Node.js in your end devices(QQ: 796448809)

View the Project on GitHub yodaos-project/ShadowNode

Platform Support

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

Timers

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.

setTimeout(callback, delay[, args..])

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);

clearTimeout(timeout)

Cancels a Timeout object created by setTimeout().

Example

var timeout = setTimeout(function() { }, 1000);
...
clearTimeout(timeout);

setInterval(callback, delay[, args..])

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);

clearInterval(timeout)

Cancels a Timeout object created by setInterval().

Example

var timeout = setInterval(function() { }, 1000);
...
clearInterval(timeout);

Class: Timeout

This object is created internally and is returned from setTimeout() and setInterval().

timeout.ref()

When called, requests that the IoT.js event loop should not exit as long as the Timeout is active.

timeout.unref()

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.