Skip to main content
版本:v3

createTimer(delay, repeat, callback, option)

创建定时器

类型

(delay: number, repeat: number, callback: (option: any) => void, option: any) => timerId

参数

参数说明必填类型默认值
delay延时(毫秒)number-
repeat周期(毫秒)number-
callback回调函数(option: any) => void-
option回调函数参数any-

timerId

说明类型
定时器句柄number

用法

//创建timer,延时500ms触发,之后每1000ms执行一次
const timer1 = timer.createTimer(
500,
1000,
function (option) {
//回调
console.log('timer callback')
console.log(option.hour)
},
{ hour: 0, minute: 15, second: 30 }
)

//停止timer1
timer.stopTimer(timer1)