From a44fa339d5318982663df6b769b07b928a42c2a5 Mon Sep 17 00:00:00 2001 From: alice <166900055+alicesaidhi@users.noreply.github.com> Date: Thu, 15 Aug 2024 02:52:46 +0200 Subject: [PATCH] simplified test case and remove error --- src/batch.luau | 2 +- src/graph.luau | 6 +----- test/tests.luau | 23 ++++++----------------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/batch.luau b/src/batch.luau index 025aab9..95ebcb2 100644 --- a/src/batch.luau +++ b/src/batch.luau @@ -16,8 +16,8 @@ local function batch(setter: () -> ()) local ok, err: string? = pcall(setter) if not already_batching then - flush() flags.batch = false + flush() end if not ok then throw(`error occured while batching updates: {err}`) end diff --git a/src/graph.luau b/src/graph.luau index 420899d..a2a0272 100644 --- a/src/graph.luau +++ b/src/graph.luau @@ -184,13 +184,10 @@ local function queue_children_for_update(node: SourceNode) update_queue.n = i end -local _flushing = false local function flush_update_queue() local n0 = update_queue.n return function() - assert(not _flushing, "recursive queue flush occured") -- todo - _flushing = true local i = n0 + 1 while i <= update_queue.n do @@ -204,10 +201,9 @@ local function flush_update_queue() update_queue[i] = false :: any i += 1 end - + update_queue.n = n0 - _flushing = false end end diff --git a/test/tests.luau b/test/tests.luau index e9e9c9b..3df56cd 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -1924,36 +1924,25 @@ TEST("batch()", wrap_root(function() do CASE "recursive queue flush" local a0 = source(0) - local a1 = source(1) - local a2 = source(0) + local a1 = source(0) local updates = 0 - derive(function() - a0(a1() + 1) + derive(function() -- depends on a1 + a0(a1()) end) - derive(function() + derive(function() -- batch updates a2 updates += 1 a0() batch(function() - a2(a0()) + end) return 1 end) - derive(function() - a2() - - batch(function() - - end) - - return 1 - end) - - a1(2) + a1(1) CHECK(updates == 2) end end))