Skip to content

Commit

Permalink
Preload fix (#34)
Browse files Browse the repository at this point in the history
* Don't try to preload if monarch is busy
* Added test for #32
  • Loading branch information
britzl authored Dec 10, 2018
1 parent 8a0a36a commit 753d003
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions monarch/monarch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ end
-- @param id (string|hash) - Id of the screen to preload
-- @param cb (function) - Optional callback to invoke when screen is loaded
function M.preload(id, cb)
if M.is_busy() then
log("preload() monarch is busy, ignoring request")
return false
end

assert(id, "You must provide a screen id")
id = tohash(id)
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
Expand Down
8 changes: 8 additions & 0 deletions test/test_monarch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ return function()
assert(wait_until_not_busy())
end)

it("should ignore any preload calls while busy", function()
monarch.show(TRANSITION1)
-- previously a call to preload() while also showing a screen would
-- lock up monarch. See issue #32
monarch.preload(TRANSITION1)
assert(wait_until_shown(TRANSITION1), "Transition1 was never shown")
end)

it("should be able to notify listeners of navigation events", function()
local URL1 = msg.url(screens_instances[hash("/listener1")])
local URL2 = msg.url(screens_instances[hash("/listener2")])
Expand Down

0 comments on commit 753d003

Please sign in to comment.