Home > SYS_Timer > setTimeoutTimer
SYS_Timer.setTimeoutTimer() method
Set a timeout timer
Signature
typescript
function setTimeoutTimer(
id: string,
timeout: number,
callFn: (...args: any) => void,
...args: any
): boolean;1
2
3
4
5
6
2
3
4
5
6
Parameters
Parameter | Type | Description |
|---|---|---|
id | string | Timer ID |
timeout | number | Timer duration, unit ms |
callFn | (...args: any) => void | Function called by the timer |
args | any | Arguments passed to the timer callback function |
Returns
boolean
Whether the timer was set successfully
Remarks
If a timer with a duplicate ID is encountered, the previously set timer will be cleared
Example
javascript
// 1. 设置 200ms 后触发一次的定时器,并给回调传参
let received = null;
const created = eda.sys_Timer.setTimeoutTimer('嘉立创示例_单次', 200, (msg) => { received = msg; }, '延时任务完成');
// 2. 等待定时器到期(单次定时器触发后自动结束,无需手动清理)
await new Promise(resolve => setTimeout(resolve, 1500));
console.log('设置结果:', created);
console.log('回调收到的参数:', received);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9