mirror of
https://github.com/centau/vide.git
synced 2026-10-20 17:34:08 +00:00
Merge f961395b3f into a4151bd41e
This commit is contained in:
commit
f684427c7f
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
|
||||
if scope.timeout == nil then
|
||||
scope.timeout = timeout(scope.delay, function() -- todo: possible redundant updates
|
||||
scope.destroy()
|
||||
local ok, err = pcall(scope.destroy)
|
||||
scopes[i] = nil
|
||||
update_output()
|
||||
if not ok then error(err, 0) end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,9 +50,10 @@ local function switch_map<K, Obj>(
|
|||
else
|
||||
if scope.timeout == nil then
|
||||
scope.timeout = timeout(scope.delay, function()
|
||||
scope.destroy()
|
||||
local ok, err = pcall(scope.destroy)
|
||||
scopes[k] = nil
|
||||
update_output()
|
||||
if not ok then error(err, 0) 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
|
||||
if scope.timeout == nil then
|
||||
scope.timeout = timeout(scope.delay, function() -- todo: possible redundant updates
|
||||
scope.destroy()
|
||||
local ok, err = pcall(scope.destroy)
|
||||
scopes[v] = nil
|
||||
update_output()
|
||||
if not ok then error(err, 0) end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1539,6 +1539,25 @@ TEST("switch()", wrap_root(function()
|
|||
do CASE "delay"
|
||||
-- probably unneeded because show() uses switch() internally
|
||||
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))
|
||||
|
||||
TEST("indexes()", wrap_root(function()
|
||||
|
|
@ -1809,6 +1828,23 @@ TEST("indexes()", wrap_root(function()
|
|||
CHECK(cleaned_counts[2] == 1)
|
||||
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))
|
||||
|
||||
TEST("values()", wrap_root(function()
|
||||
|
|
@ -2024,6 +2060,23 @@ TEST("values()", wrap_root(function()
|
|||
--CHECK(count == 3)
|
||||
CHECK(count == 5)
|
||||
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))
|
||||
|
||||
TEST("spring()", wrap_root(function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue