Implement batched updates

No docs yet, more testing needed.
This commit is contained in:
Aaron Smith 2023-10-27 16:47:49 +01:00
parent 7d82fe353e
commit ec998ccbc8
6 changed files with 123 additions and 10 deletions

23
src/batch.luau Normal file
View file

@ -0,0 +1,23 @@
if not game then script = require "test/relative-string" end
local flags = require(script.Parent.flags)
local throw = require(script.Parent.throw)
local graph = require(script.Parent.graph)
local function batch(setter: () -> ())
local already_batching = flags.batch
flags.batch = true
local ok, err: string? = pcall(setter)
flags.batch = false
if not ok then throw(`error occured while batching updates: {err}`) end
if not already_batching then -- todo: flush anyways?
graph.flush_update_queue()
end
end
return batch