3
0
mirror of https://github.com/britzl/monarch.git synced 2025-09-27 18:12:22 +02:00

Transition out and in again if showing the same screen twice

Fixes #54
This commit is contained in:
Björn Ritzl
2019-09-14 01:23:14 +02:00
parent 8001d370c2
commit 81237762be
3 changed files with 33 additions and 17 deletions

View File

@@ -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