dp-s_doc/Object/Timer/Timer.md

64 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Timer 类函数文档
**类说明**
`Timer`类为定时器相关操作。
---
### 函数签名
**公有函数**
- `function SetTimeOut(target_func, delay_time, ...)`
### 参数
- `target_func`:函数体,要获执行的函数
- `delay_time`:整数,要延迟的时间(秒)
- `...`:可变参数,传入的参数可再函数体回调函数中使用
**这里给出两个个例子**
> 无参数
```
Timer.SetTimeOut(function() {
print("注册 5 秒后执行")
}, 5);
```
---
> 有参数
```
Timer.SetTimeOut(function(str,num) {
print(str);//将打印 "字符串"
print(num);//将打印 123
print("注册 5 秒后执行")
}, 5,"字符串",123);
```
---
---
### 函数签名
**公有函数**
- `function SetCronTask(target_func, CronString, ...)`
### 参数
- `target_func`:函数体,要获执行的函数
- `CronString`:字符串,计划任务格式 让gpt帮你写cron字符串
- `...`:可变参数,传入的参数可再函数体回调函数中使用
**这里给出两个个例子**
> 无参数
```
Timer.SetCronTask(function() {
print("注册 每五秒 执行")
}, "*/5 * * * * ?");
```
---
> 有参数
```
Timer.SetCronTask(function(str,num) {
print(str);//将打印 "字符串"
print(num);//将打印 123
print("注册 每五秒 执行")
}, "*/5 * * * * ?","字符串",123);
```
---