1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
timer.md 17.61 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

Timer

Module to Import

None

Permission List

None

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

Sets a timer for the system to call a function after the timer goes off.

  • Parameters

    Name

    Type

    Mandatory

    Description

    handler

    Function

    Yes

    Function to be called after the timer goes off.

    delay

    number

    No

    Number of milliseconds delayed before the execution. If this parameter is left empty, the default value 0 is used, which means that the execution starts immediately or as soon as possible.

    ...args

    Array<any>

    No

    Additional parameter to pass to the handler after the timer goes off.

  • Return Value

    timeoutID: timer ID

  • Example

    var timeoutID = setTimeout(function() {
      console.log('delay 1s');
    }, 1000);

clearTimeout(timeoutID)

Cancels the timer created via setTimeout().

  • Parameter

    Name

    Type

    Mandatory

    Description

    timeoutID

    number

    Yes

    ID of the timer to cancel, which is returned by setTimeout()

  • Example

    var timeoutID = setTimeout(function() {
      console.log('do after 1s delay.');
    }, 1000);
    
    clearTimeout(timeoutID);

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

Sets a repeating timer for the system to repeatedly call a function at a fixed interval.

  • Parameters

    Name

    Type

    Mandatory

    Description

    handler

    Function

    Yes

    Function to be called repeatedly

    delay

    number

    No

    Number of milliseconds delayed before the execution

    ...args

    Array<any>

    No

    Additional parameter to pass to the handler after the timer goes off

  • Return Value

    intervalID: ID of the repeating timer

  • Example

    var intervalID = setInterval(function() {
      console.log('do very 1s.');
    }, 1000);

clearInterval(intervalID)

Cancels the repeating timer set via setInterval().

  • Parameter

    Name

    Type

    Mandatory

    Description

    intervalID

    number

    Yes

    ID of the repeating timer to cancel, which is returned by setInterval().

  • Example

    var intervalID = setInterval(function() {
      console.log('do very 1s.');
    }, 1000);
    
    clearInterval(intervalID);
1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助