Functions
timerWithControl()
timerWithControl(
callback
,options
):object
创建可控的定时器
注意:不支持自动执行回调,需手动调用 start()
或 flush()
执行回调!
Parameters
Parameter | Type | Description |
---|---|---|
callback | Fn <[], void > | 回调句柄 |
options | TimerWithControlOptions | 配置项 |
Returns
object
flush()
flush: () =>
void
停止定时器并立即执行回调
Returns
void
isActive()
isActive: () =>
boolean
判断定时器是否处于激活状态
Returns
boolean
start()
start: () =>
void
启动定时器
Returns
void
stop()
stop: (
cleanup
) =>void
停止定时器
Parameters
Parameter | Type | Default value |
---|---|---|
cleanup | boolean | false |
Returns
void
Example
ts
const timer = timerWithControl(() => {
console.log(Date.now())
})
// 启动定时器
timer.start()
// 停止定时器
timer.stop()
// 停止定时器并立即执行回调
timer.flush()