This commit is contained in:
Kaan 2026-10-19 17:49:37 +03:00 • committed by GitHub
commit f684427c7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 59 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()