mirror of
https://github.com/centau/vide.git
synced 2026-10-21 20:01:37 +00:00
Fix destroyed components staying in the output when a delayed cleanup errors
This commit is contained in:
parent
a4151bd41e
commit
f961395b3f
4 changed files with 59 additions and 3 deletions
|
|
@ -101,9 +101,10 @@ local function indexes<K, V, Obj>(
|
||||||
scope.value = nil -- set to nil for the `scope.value ~= v` check
|
scope.value = nil -- set to nil for the `scope.value ~= v` check
|
||||||
if scope.timeout == nil then
|
if scope.timeout == nil then
|
||||||
scope.timeout = timeout(scope.delay, function() -- todo: possible redundant updates
|
scope.timeout = timeout(scope.delay, function() -- todo: possible redundant updates
|
||||||
scope.destroy()
|
local ok, err = pcall(scope.destroy)
|
||||||
scopes[i] = nil
|
scopes[i] = nil
|
||||||
update_output()
|
update_output()
|
||||||
|
if not ok then error(err, 0) end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,10 @@ local function switch_map<K, Obj>(
|
||||||
else
|
else
|
||||||
if scope.timeout == nil then
|
if scope.timeout == nil then
|
||||||
scope.timeout = timeout(scope.delay, function()
|
scope.timeout = timeout(scope.delay, function()
|
||||||
scope.destroy()
|
local ok, err = pcall(scope.destroy)
|
||||||
scopes[k] = nil
|
scopes[k] = nil
|
||||||
update_output()
|
update_output()
|
||||||
|
if not ok then error(err, 0) end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,10 @@ local function values<K, V, Obj>(
|
||||||
scope.index = nil -- set to nil for the `scope.index ~= i` check
|
scope.index = nil -- set to nil for the `scope.index ~= i` check
|
||||||
if scope.timeout == nil then
|
if scope.timeout == nil then
|
||||||
scope.timeout = timeout(scope.delay, function() -- todo: possible redundant updates
|
scope.timeout = timeout(scope.delay, function() -- todo: possible redundant updates
|
||||||
scope.destroy()
|
local ok, err = pcall(scope.destroy)
|
||||||
scopes[v] = nil
|
scopes[v] = nil
|
||||||
update_output()
|
update_output()
|
||||||
|
if not ok then error(err, 0) end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1539,6 +1539,25 @@ TEST("switch()", wrap_root(function()
|
||||||
do CASE "delay"
|
do CASE "delay"
|
||||||
-- probably unneeded because show() uses switch() internally
|
-- probably unneeded because show() uses switch() internally
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "delay with cleanup error"
|
||||||
|
local input = source(1)
|
||||||
|
local errored = false
|
||||||
|
|
||||||
|
local output = switch(input) {
|
||||||
|
[1] = function()
|
||||||
|
cleanup(function()
|
||||||
|
if not errored then errored = true; error("cleanup error") end
|
||||||
|
end)
|
||||||
|
return 1, 1
|
||||||
|
end,
|
||||||
|
[2] = function() return 2 end
|
||||||
|
}
|
||||||
|
|
||||||
|
input(2)
|
||||||
|
CHECK(not pcall(step, 1 + 0.01))
|
||||||
|
CHECK(output() == 2)
|
||||||
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
TEST("indexes()", wrap_root(function()
|
TEST("indexes()", wrap_root(function()
|
||||||
|
|
@ -1809,6 +1828,23 @@ TEST("indexes()", wrap_root(function()
|
||||||
CHECK(cleaned_counts[2] == 1)
|
CHECK(cleaned_counts[2] == 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "delay with cleanup error"
|
||||||
|
local input = source { 1 }
|
||||||
|
local errored = false
|
||||||
|
|
||||||
|
local output = indexes(input, function()
|
||||||
|
cleanup(function()
|
||||||
|
if not errored then errored = true; error("cleanup error") end
|
||||||
|
end)
|
||||||
|
return {}, 1
|
||||||
|
end)
|
||||||
|
|
||||||
|
input {}
|
||||||
|
CHECK(#output() == 1)
|
||||||
|
CHECK(not pcall(step, 1 + 0.01))
|
||||||
|
CHECK(#output() == 0)
|
||||||
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
TEST("values()", wrap_root(function()
|
TEST("values()", wrap_root(function()
|
||||||
|
|
@ -2024,6 +2060,23 @@ TEST("values()", wrap_root(function()
|
||||||
--CHECK(count == 3)
|
--CHECK(count == 3)
|
||||||
CHECK(count == 5)
|
CHECK(count == 5)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "delay with cleanup error"
|
||||||
|
local input = source { 1 }
|
||||||
|
local errored = false
|
||||||
|
|
||||||
|
local output = values(input, function()
|
||||||
|
cleanup(function()
|
||||||
|
if not errored then errored = true; error("cleanup error") end
|
||||||
|
end)
|
||||||
|
return {}, 1
|
||||||
|
end)
|
||||||
|
|
||||||
|
input {}
|
||||||
|
CHECK(#output() == 1)
|
||||||
|
CHECK(not pcall(step, 1 + 0.01))
|
||||||
|
CHECK(#output() == 0)
|
||||||
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
TEST("spring()", wrap_root(function()
|
TEST("spring()", wrap_root(function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue