mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 12:41:37 +00:00
refactor: check type of cleanup
This commit is contained in:
parent
b00e6760c0
commit
e460846dea
1 changed files with 11 additions and 7 deletions
|
|
@ -226,11 +226,13 @@ local function run(effect: EffectNode)
|
||||||
|
|
||||||
purgeDeps(effect)
|
purgeDeps(effect)
|
||||||
|
|
||||||
if not success then
|
if success then
|
||||||
error(result, 0)
|
if type(result) == "function" then
|
||||||
elseif result then
|
|
||||||
table.insert(effect.cleanups, wrapUserSpace(result))
|
table.insert(effect.cleanups, wrapUserSpace(result))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
error(result, 0)
|
||||||
|
end
|
||||||
|
|
||||||
-- If the effect was disposed during execution but before a cleanup was
|
-- If the effect was disposed during execution but before a cleanup was
|
||||||
-- was registered, run the cleanups that would have been missed
|
-- was registered, run the cleanups that would have been missed
|
||||||
|
|
@ -627,7 +629,7 @@ local function effect(fn: () -> ...Cleanup?): Cleanup
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
if result then
|
if type(result) == "function" then
|
||||||
table.insert(node.cleanups, wrapUserSpace(result))
|
table.insert(node.cleanups, wrapUserSpace(result))
|
||||||
end
|
end
|
||||||
endBatch()
|
endBatch()
|
||||||
|
|
@ -665,11 +667,13 @@ local function effectScope(fn: () -> ...Cleanup?, detached: boolean?): Cleanup
|
||||||
local success, result = pcall(wrapUserSpace(fn))
|
local success, result = pcall(wrapUserSpace(fn))
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not success then
|
if success then
|
||||||
error(result, 2)
|
if type(result) == "function" then
|
||||||
elseif result then
|
|
||||||
table.insert(node.cleanups, wrapUserSpace(result))
|
table.insert(node.cleanups, wrapUserSpace(result))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
error(result, 2)
|
||||||
|
end
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
stopEffect(node)
|
stopEffect(node)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue