fix recursive queue flush (#28)

* fix recursive queue flush

* remove print from test

* swap order of flush

* simplified test case and remove error

* write more in-depth tests

* change approach flush_update_queue

* double diamond test case

* fix indent

* change naming of function

* subsequent updates do not batch test case

* simplify test case
This commit is contained in:
alicesaidhi 2024-08-20 13:44:56 +02:00 committed by GitHub
parent b85419088c
commit fbe2f01bb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 219 additions and 16 deletions

View file

@ -6,17 +6,18 @@ local graph = require(script.Parent.graph)
local function batch(setter: () -> ())
local already_batching = flags.batch
local from
flags.batch = true
if not already_batching then
flags.batch = true
from = graph.get_update_queue_length()
end
local ok, err: string? = pcall(setter)
if not already_batching then
flags.batch = false
if not already_batching then
graph.flush_update_queue()
end
graph.flush_update_queue(from)
end
if not ok then throw(`error occured while batching updates: {err}`) end

View file

@ -184,14 +184,12 @@ local function queue_children_for_update<T>(node: SourceNode<T>)
update_queue.n = i
end
local _flushing = false
local function flush_update_queue()
assert(not _flushing, "recursive queue flush occured") -- todo
_flushing = true
local function get_update_queue_length()
return update_queue.n
end
local n0 = 0
local i = n0 + 1
local function flush_update_queue(from: number)
local i = from + 1
while i <= update_queue.n do
local node = update_queue[i]
--assert(node.effect)
@ -203,10 +201,8 @@ local function flush_update_queue()
update_queue[i] = false :: any
i += 1
end
update_queue.n = n0
_flushing = false
update_queue.n = from
end
local function update_descendants<T>(root: SourceNode<T>)
@ -286,5 +282,6 @@ return table.freeze {
create_source_node = create_source_node,
get_children = get_children,
flush_update_queue = flush_update_queue,
get_update_queue_length = get_update_queue_length,
scopes = scopes
}