Skip to content

Commit

Permalink
Merge pull request #45 from nezuo/infinite-game-close-yield-fix
Browse files Browse the repository at this point in the history
Fix infinite yield in BindToClose when a document fails to load
  • Loading branch information
nezuo authored Apr 9, 2024
2 parents 8b80abd + bbb79b4 commit 9c9a2ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Collection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/init.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9c9a2ab

Please sign in to comment.