函数:thread.clearTimeout 清除协程超时时间

函数名称:清除协程超时时间

函数功能:清除协程超时时间

引擎版本:iOS v2.3.9,Android v2.3.4 以上

函数方法

thread.clearTimeout(thread_id)

返回值:无

参数 必填 类型 说明
thread_id number 协程 ID,如果在协程内,参数省略

函数用例

thread = require("thread")
local ts = require("ts")--使用扩展库前必须插入这一句
local json = ts.json--使用 JSON 模块前必须插入这一句
local thread_id = thread.create(function()
        thread.setTimeout(2000)
        mSleep(1000)
        toast("thread step 1")
        mSleep(2000)
        toast("thread step 2")
        mSleep(3000)
        --设置有超时,执行不到这了,会调用 catchBack
        toast("thread over")

    end,{
        callBack = function()
            --协程结束会调用,不论是错误、异常、正常结束
            --        toast("我结束了")
        end,
        catchBack = function(exp)
            --协程异常结束,异常是脚本调用了 throw 激发的,exp 是 table,exp.message 是异常原因

            toast("我异常了"..json.encode(exp))
        end
    })
mSleep(1000)
thread.clearTimeout(thread_id)
mSleep(2000)
thread.setTimeout(1000,thread_id)
--等待所有协程结束
thread.waitAllThreadExit()
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""