Home > SYS_Timer > clearTimeoutTimer
SYS_Timer.clearTimeoutTimer() method
清除指定单次定时器
签名
typescript
function clearTimeoutTimer(id: string): boolean;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
id | string | 定时器 ID |
返回值
boolean
定时器是否清除成功
示例
javascript
// 1. 挂一个 2 秒后才触发的定时器
let fired = false;
eda.sys_Timer.setTimeoutTimer('嘉立创示例_取消单次', 2000, () => { fired = true; });
// 2. 在触发前清除它
const cleared = eda.sys_Timer.clearTimeoutTimer('嘉立创示例_取消单次');
// 3. 对已清除的 ID 再清除一次,返回 false(定时器已不存在)
const again = eda.sys_Timer.clearTimeoutTimer('嘉立创示例_取消单次');
// 4. 等过原定触发时间,确认回调没有被触发
await new Promise(resolve => setTimeout(resolve, 1000));
console.log('清除结果:', cleared);
console.log('再次清除同一 ID:', again);
console.log('回调是否仍被触发:', fired);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16