diff --git a/src/batch.luau b/src/batch.luau index 95ebcb2..025aab9 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 - flags.batch = false flush() + flags.batch = false end if not ok then throw(`error occured while batching updates: {err}`) end diff --git a/test/tests.luau b/test/tests.luau index edcd0e2..e9e9c9b 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -1925,26 +1925,36 @@ TEST("batch()", wrap_root(function() local a0 = source(0) local a1 = source(1) + local a2 = source(0) + local updates = 0 derive(function() a0(a1() + 1) end) derive(function() + updates += 1 a0() batch(function() + a2(a0()) + end) + + return 1 + end) + + derive(function() + a2() + batch(function() + end) return 1 end) a1(2) - - -- if it didnt error, all is fine! - CHECK(true) - + CHECK(updates == 2) end end))