TSR_ECS/main/scripts/thread.lua
2023-12-25 18:47:55 +01:00

35 lines
539 B
Lua

-- thread utils
function wait(t)
coroutine.yield(t)
end
function thread(cb)
local co = coroutine.create(cb)
local function resumefun()
if coroutine.status(co) == "dead" then
return
end
local suc, time = coroutine.resume(co)
if not suc then
error(debug.traceback(co))
end
if suc and time then
g_settimer(time, false, resumefun)
end
end
resumefun()
return co
end
function killthread(co)
coroutine.close(co)
end