zoukankan      html  css  js  c++  java
  • GPRS(Air202) Lua开发: 定时器

    1.延时

    sys.wait(5000) --延时5S

    延时函数一般配合任务使用

    --启动任务
    sys.taskInit(
    function()
            while true do
                log.info("test sys.wait")
                sys.wait(1000) --延时1S
            end
        end
    )

    2.一次性定时器

    function OneTimer(param)
        print(param);
    end
    
    --一次性定时器: sys.timerStart
    --OneTimer:回调函数
    --5000:延时5S
    --最后一个参数:传给回调函数的参数
    sys.timerStart(OneTimer,5000,"这是一个参数")

    3.循环定时器

    local cnt = 0;
    function LoopTimer(param)
        print(param)
        cnt = cnt+1
        if(cnt>=6) then
            cnt = 0;
            sys.timerStop(timerLoop) --停止循环定时器
            print("停止循环定时器")
        end
    end
    
    --一次性定时器: sys.timerStart
    --OneTimer:回调函数
    --1000:延时1S
    --最后一个参数:传给回调函数的参数
    --timerLoop:返回的参数用于关闭定时器
    timerLoop = sys.timerLoopStart(LoopTimer,1000,"这是循环定时器")

     

    4.补充(关闭定时器的第二种方式)

    --sys.timerStopAll(LoopTimer) --LoopTimer:关闭与此回调函数绑定的所有定时器

     

  • 相关阅读:
    Windows多线程编程入门
    多字节字符与宽字符
    Linux静态库与动态库详解
    Linux下清理内存和Cache方法
    数据库设计范式
    mybatis面试问题
    Gson使用
    Linux 定时任务crontab使用
    Java-GC机制
    java内存模型
  • 原文地址:https://www.cnblogs.com/yangfengwu/p/12955709.html
Copyright © 2011-2022 走看看