函数:thread.stop 停止协程队列

函数名称:停止协程队列

函数功能:停止一个协程队列,如果协程中有子协程,一并结束

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

函数方法

thread.stop(tid)

返回值:无

参数 类型 必填 说明
tid number 协程 ID,ID 可用于结束或是等待一个任务

函数用例

local thread = require('thread')
local thread_id1 = thread.create(function()
    for i=1,10 do
        toast("协程 1:".. i)
        mSleep(1200)
    end
end)
local thread_id2 = thread.create(function()
    for i=1,10 do
        toast("协程2:".. i)
        mSleep(2000)
    end
end)
mSleep(5000)
--关闭协程 1
thread.stop(thread_id1)
--等待所有协程结束,只能用于主线程
thread.waitAllThreadExit()
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""