|  | 
 
| 
 
 延时
 
 sys.wait(5000) --延时5S
 
 延时函数一般配合任务使用 
 sys.taskInit(function()
 while 1 do
 sys.wait(500) --延时500ms
 log.info("111111111111111111111111")
 end
 end)
 
 
 
 
 一次性定时器
 
 
 -- 一次性定时器
 function OneTimer(param)
 print(param);
 end
 
 
 --一次性定时器: sys.timerStart
 --OneTimer:回调函数
 --5000:延时5S
 --最后一个参数:传给回调函数的参数
 sys.timerStart(OneTimer,5000,"delay 5s")
 
 
 
  程序启动延时5S后打印 
 
 
 循环定时器
 
 -- 循环定时器
 local cnt = 0;
 function LoopTimer(param)
 print(param)
 cnt = cnt+1
 if(cnt>=6) then
 cnt = 0;
 sys.timerStop(timerLoop) --停止循环定时器
 print("stop timerLoop")
 end
 end
 
 
 --循环定时器: sys.timerLoopStart
 --LoopTimer:回调函数
 --1000:延时1S
 --最后一个参数:传给回调函数的参数
 --timerLoop:返回的参数用于关闭定时器
 timerLoop = sys.timerLoopStart(LoopTimer,1000,"this timerLoop")
 
 
 
 
 
 
 | 
 |