mirror of
https://github.com/britzl/monarch.git
synced 2025-06-27 10:27:49 +02:00
pcall in the callback tracker
This commit is contained in:
parent
7e2ff2990c
commit
7d986ada1b
@ -7,15 +7,20 @@ function M.create()
|
||||
local callback = nil
|
||||
local callback_count = 0
|
||||
|
||||
local function invoke_if_done()
|
||||
if callback_count == 0 and callback then
|
||||
local ok, err = pcall(callback)
|
||||
if not ok then print(err) end
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a callback function and track when it is done
|
||||
-- @return Callback function
|
||||
function instance.track()
|
||||
callback_count = callback_count + 1
|
||||
return function()
|
||||
callback_count = callback_count - 1
|
||||
if callback_count == 0 and callback then
|
||||
callback()
|
||||
end
|
||||
invoke_if_done()
|
||||
end
|
||||
end
|
||||
|
||||
@ -23,9 +28,7 @@ function M.create()
|
||||
-- @param cb Function to call when all
|
||||
function instance.when_done(cb)
|
||||
callback = cb
|
||||
if callback_count == 0 then
|
||||
callback()
|
||||
end
|
||||
invoke_if_done()
|
||||
end
|
||||
|
||||
return instance
|
||||
|
Loading…
x
Reference in New Issue
Block a user