feat: pass cleanup function to effect (#40)

This commit is contained in:
richard 2025-01-25 12:14:21 -08:00 • committed by GitHub
parent 6be2fbb746
commit 89f1dfeaa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 11 deletions

View file

@ -93,4 +93,19 @@ return function()
a(2)
a(3)
end)
it("allows immediate self-cleanup", function()
local a = atom(1)
local cleanedUp = false
effect(function(cleanup)
assert(not cleanedUp, "cleanup ran twice")
cleanup()
cleanedUp = true
a()
end)
a(2)
a(3)
end)
end