Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加coroutine.wait_until工具函数 #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Assets/ToLua/Lua/System/coroutine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@ function coroutine.step(t, co, ...)
return yield()
end

function coroutine.wait_until(conditionFunc, co)
co = co or running()
local timer = nil

local action = function()
if not conditionFunc() then
return
end

comap[co] = nil
timer:Stop()
timer.func = nil
local flag, msg = resume(co)
table.insert(pool, timer)
if not flag then
error(debug.traceback(co, msg))
return
end
end

if #pool > 0 then
timer = table.remove(pool)
timer:Reset(action, 1, -1)
else
timer = FrameTimer.New(action, 1, -1)
end

comap[co] = timer
timer:Start()
return yield()
end

function coroutine.www(www, co)
co = co or running()
local timer = nil
Expand Down