mirror of
https://github.com/centau/vide.git
synced 2026-10-22 20:54:09 +00:00
Keep the graph consistent when effects or cleanups error (#100)
* Keep the graph consistent when effects or cleanups error * Fix effect updating its own source looping in strict mode
This commit is contained in:
parent
a4151bd41e
commit
b24666fc57
2 changed files with 134 additions and 42 deletions
|
|
@ -633,6 +633,25 @@ TEST("effect()", wrap_root(function()
|
|||
|
||||
CHECK(count == 2)
|
||||
end
|
||||
|
||||
do CASE "error does not stop other effects"
|
||||
local src = source(0)
|
||||
|
||||
local count = 0
|
||||
effect(function()
|
||||
if src() == 1 then error("effect error") end
|
||||
end)
|
||||
effect(function()
|
||||
src()
|
||||
count += 1
|
||||
end)
|
||||
|
||||
CHECK(count == 1)
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count == 2)
|
||||
src(2)
|
||||
CHECK(count == 3)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("cleanup()", wrap_root(function()
|
||||
|
|
@ -709,6 +728,46 @@ TEST("cleanup()", wrap_root(function()
|
|||
CHECK(ran.destroy)
|
||||
CHECK(ran.Destroy)
|
||||
end
|
||||
|
||||
do CASE "error does not stop destruction"
|
||||
local src = source(0)
|
||||
|
||||
local cleaned = false
|
||||
local count = 0
|
||||
|
||||
local destroy = root(function()
|
||||
cleanup(function() error("cleanup error") end)
|
||||
cleanup(function() cleaned = true end)
|
||||
effect(function()
|
||||
src()
|
||||
count += 1
|
||||
end)
|
||||
end)
|
||||
|
||||
CHECK(not pcall(destroy))
|
||||
CHECK(cleaned)
|
||||
src(1)
|
||||
CHECK(count == 1)
|
||||
end
|
||||
|
||||
do CASE "error on rerun does not stop updates"
|
||||
local src = source(0)
|
||||
|
||||
local count = 0
|
||||
effect(function()
|
||||
src()
|
||||
cleanup(function() if src() == 1 then error("cleanup error") end end)
|
||||
end)
|
||||
effect(function()
|
||||
src()
|
||||
count += 1
|
||||
end)
|
||||
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count == 2)
|
||||
src(2)
|
||||
CHECK(count == 3)
|
||||
end
|
||||
end))
|
||||
|
||||
TEST("create()", wrap_root(function()
|
||||
|
|
@ -3112,6 +3171,21 @@ TEST("strict", wrap_root(function()
|
|||
CHECK(count == 4)
|
||||
end
|
||||
|
||||
do CASE "effect updating its own source"
|
||||
local src = source(0)
|
||||
local count = 0
|
||||
|
||||
effect(function()
|
||||
count += 1
|
||||
if count > 100 then return end
|
||||
local v = src()
|
||||
if v > 0 then src(v + 1) end
|
||||
end)
|
||||
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count < 100)
|
||||
end
|
||||
|
||||
do CASE "destruction of active scope"
|
||||
local src = source(false)
|
||||
local count = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue