mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 21:01:38 +00:00
refactor: error for effect cleanup errors
This commit is contained in:
parent
c52f55a55e
commit
748dbc5014
1 changed files with 11 additions and 3 deletions
|
|
@ -178,6 +178,9 @@ end
|
||||||
@param cleanups List of cleanup functions
|
@param cleanups List of cleanup functions
|
||||||
]]
|
]]
|
||||||
local function runCleanups(cleanups: { Cleanup })
|
local function runCleanups(cleanups: { Cleanup })
|
||||||
|
local hasErrors = false
|
||||||
|
local errors = {}
|
||||||
|
|
||||||
for index, cleanup in cleanups do
|
for index, cleanup in cleanups do
|
||||||
cleanups[index] = nil
|
cleanups[index] = nil
|
||||||
|
|
||||||
|
|
@ -186,9 +189,14 @@ local function runCleanups(cleanups: { Cleanup })
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
warn("Error occurred during effect cleanup:", result)
|
hasErrors = true
|
||||||
|
table.insert(errors, tostring(result))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if hasErrors then
|
||||||
|
error(`Errors occurred during effect cleanup:\n\n${table.concat(errors, "\n\n")}`, 0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
@ -404,14 +412,14 @@ local function notify(effect: ReactiveNode)
|
||||||
queuedLength = insertIndex
|
queuedLength = insertIndex
|
||||||
|
|
||||||
-- Reverse the collected effects to ensure outer effects run first
|
-- Reverse the collected effects to ensure outer effects run first
|
||||||
while true do
|
repeat
|
||||||
insertIndex -= 1
|
insertIndex -= 1
|
||||||
if firstInsertedIndex >= insertIndex then
|
if firstInsertedIndex >= insertIndex then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
queued[firstInsertedIndex], queued[insertIndex] = queued[insertIndex], queued[firstInsertedIndex]
|
queued[firstInsertedIndex], queued[insertIndex] = queued[insertIndex], queued[firstInsertedIndex]
|
||||||
firstInsertedIndex += 1
|
firstInsertedIndex += 1
|
||||||
end
|
until false
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue