mirror of
https://github.com/britzl/monarch.git
synced 2025-09-28 10:32:21 +02:00
@@ -7,6 +7,10 @@ function M.create()
|
||||
local callback = nil
|
||||
local callback_count = 0
|
||||
|
||||
local function is_done()
|
||||
return callback_count == 0
|
||||
end
|
||||
|
||||
local function invoke_if_done()
|
||||
if callback_count == 0 and callback then
|
||||
local ok, err = pcall(callback)
|
||||
@@ -37,6 +41,17 @@ function M.create()
|
||||
invoke_if_done()
|
||||
end
|
||||
|
||||
function instance.yield_until_done()
|
||||
local co = coroutine.running()
|
||||
callback = function()
|
||||
coroutine.resume(co)
|
||||
end
|
||||
invoke_if_done()
|
||||
if not is_done() then
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user