From 753d00386172388c920c632f1bd923fed8ff7b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Mon, 10 Dec 2018 12:27:11 +0100 Subject: [PATCH] Preload fix (#34) * Don't try to preload if monarch is busy * Added test for #32 --- monarch/monarch.lua | 5 +++++ test/test_monarch.lua | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index 4642934..50d79dd 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -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))) diff --git a/test/test_monarch.lua b/test/test_monarch.lua index 3a04f47..1f9987e 100644 --- a/test/test_monarch.lua +++ b/test/test_monarch.lua @@ -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")])