1 Star 0 Fork 2

scriptiot / evm_doc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
evm_class_timers.md 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
edmundwz 提交于 2021-02-20 16:13 . update

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..])

  • callback {Function} The function to call when the timer elapses.
    • ...args {any}
  • delay {number} The number of milliseconds to wait before calling the callback.
  • ...args {any} - Optional arguments to pass when the callback 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);

clearTimeout(timeout)

  • timeout {Timeout} A Timeout object returned by setTimeout().

Cancels a Timeout object created by setTimeout().

Example

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

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

  • callback {Function} The function to call when the timer elapses.
    • ...args {any}
  • delay {number} The number of milliseconds to wait before calling the callback.
  • ...args {any} - Optional arguments to pass when the callback 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);

clearInterval(timeout)

  • timeout {Timeout} A Timeout object as returned by setInterval().

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 activities, the process may exit, the process may exit before the Timeout object's callback is invoked.

1
https://gitee.com/scriptiot/evm_doc.git
git@gitee.com:scriptiot/evm_doc.git
scriptiot
evm_doc
evm_doc
master

搜索帮助