diff --git a/CHANGELOG.md b/CHANGELOG.md index c75dd6a..efb88b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Lapis Changelog ## Unreleased Changes +* Fix infinite yield in `game:BindToClose` caused by a document failing to load. ([#45]) + +[#45]: https://github.com/nezuo/lapis/pull/45 ## 0.2.10 - March 25, 2024 * `Document:load` now infinitely yields and doesn't load the document after `game:BindToClose` is called. If a document diff --git a/src/Collection.lua b/src/Collection.lua index c520a66..676f069 100644 --- a/src/Collection.lua +++ b/src/Collection.lua @@ -120,6 +120,7 @@ function Collection:load(key, defaultUserIds) :finally(function(status) if status ~= Promise.Status.Resolved then self.openDocuments[key] = nil + self.autoSave.ongoingLoads -= 1 end end) end diff --git a/src/init.test.lua b/src/init.test.lua index 930ee9a..bc430ac 100644 --- a/src/init.test.lua +++ b/src/init.test.lua @@ -390,5 +390,21 @@ return function(x) assert(coroutine.status(thread) == "dead", "") end) + + x.test("BindToClose should finish if a document fails to load", function(context) + local collection = context.lapis.createCollection("collection", DEFAULT_OPTIONS) + + context.write("collection", "document", "INVALID DATA") + collection:load("document"):catch(function() end) + + -- Wait to close game so that the save request doesn't get cancelled. + task.wait(0.1) + + Promise.try(function() + context.lapis.autoSave:onGameClose() + end) + :timeout(1) + :expect() + end) end) end