This commit is contained in:
Aaron Smith 2023-09-11 17:41:05 +01:00
parent dcc40b4dc1
commit 52ea2e4690
9 changed files with 147 additions and 102 deletions

View file

@ -11,6 +11,8 @@ local close_scope = graph.close_scope
local get_scope = graph.get_scope
local destroy = graph.destroy
local refs = {}
local function root<T>(fn: () -> T): (T, () -> ())
--assert(not get_scope())
local node = create_node(false)
@ -21,7 +23,10 @@ local function root<T>(fn: () -> T): (T, () -> ())
close_scope()
refs[node] = true
return v, function()
refs[node] = nil
destroy(node)
end
end