nice-timer
Version:
Timer
47 lines (43 loc) • 1.17 kB
text/typescript
export type KeyType = string | symbol;
export type Handler = (params: TimerOption) => void;
/**
* time 定时时间
*
* cb 回调函数,定时后运行
*
* loop 是否循环或者循环次数
*
* check 检查函数,什么时候开始运行什么时候停止运行,返回true表示开始运行,返回false停止运行,返回false时不运行cb但是该total还是会继续叠加
*
* timerKey 定时任务的标识符,相同的 timerKey 将进行替换传递进来的其他参数,定时任务将按照新的参数进行运行
*/
export interface CreateOption {
time: number;
cb: Handler;
loop?: boolean | number;
check?(params: TimerOption): boolean;
timerKey?: KeyType;
[key: KeyType]: any;
}
/**
* id 定时任务的标识符
*
* lastTime 最后一次的运行时间
*
* total 总运行次数
*
* times 实际运行次数
*
* targetCloseHandler 关闭当前任务函数
*/
export interface TimerOption extends CreateOption {
id: symbol;
lastTime: number;
total: number;
times: number;
targetCloseHandler: () => void;
}
export type TimerId = TimerOption['id'];
export interface Option {
[key: KeyType]: any;
}