From cdc390cde697890b02fd9e047ba54efdfa4e91db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 26 May 2026 21:13:44 +0200 Subject: [PATCH] Add concurrency test --- packages/effect-lens/src/Lens.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/effect-lens/src/Lens.test.ts b/packages/effect-lens/src/Lens.test.ts index 1c3c794..8d84d2f 100644 --- a/packages/effect-lens/src/Lens.test.ts +++ b/packages/effect-lens/src/Lens.test.ts @@ -208,6 +208,31 @@ describe("Lens", () => { expect(result[1]).toBe(25) }) + test("modifyEffect updates are atomic under concurrency", async () => { + const iterations = 100 + + const result = await Effect.runPromise(Effect.flatMap( + SubscriptionRef.make({ count: 0 }), + parent => { + const countLens = Lens.focusObjectOn(Lens.fromSubscriptionRef(parent), "count") + + return Effect.flatMap( + Effect.forEach( + Array.from({ length: iterations }), + () => Lens.updateEffect( + countLens, + count => Effect.as(Effect.yieldNow(), count + 1), + ), + { concurrency: "unbounded", discard: true }, + ), + () => parent.get, + ) + }, + )) + + expect(result.count).toBe(iterations) + }) + test("focusObjectOn focuses a nested property without touching other fields", async () => { const [initialCount, updatedState] = await Effect.runPromise( Effect.flatMap(