From 603c48e698444cbf5482528f2b2ad13c9b66e3c9 Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Thu, 9 Apr 2026 17:36:40 -0400 Subject: [PATCH] chore: use Node 24, update examples to use `using` for pool disposal Co-Authored-By: Claude Opus 4.6 (1M context) --- .node-version | 1 + examples/atomics/main.ts | 9 +++++---- examples/non-blocking/main.ts | 17 +++++++++-------- examples/parallel-batch/main.ts | 14 ++++++++------ 4 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 .node-version diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..a45fd52 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +24 diff --git a/examples/atomics/main.ts b/examples/atomics/main.ts index 8939f27..cc3420d 100644 --- a/examples/atomics/main.ts +++ b/examples/atomics/main.ts @@ -6,12 +6,13 @@ import { pool, int32atomic } from '../../src/index.ts'; import { increment } from './increment.ts'; const counter = int32atomic(); -const run = pool(4); -// Fire off 100 increments across 4 workers -await Promise.all(Array.from({ length: 100 }, () => run(increment(counter)))); +{ + using run = pool(4); -run[Symbol.dispose](); + // Fire off 100 increments across 4 workers + await Promise.all(Array.from({ length: 100 }, () => run(increment(counter)))); +} console.log(`Expected: 100`); console.log(`Actual: ${counter.load()}`); diff --git a/examples/non-blocking/main.ts b/examples/non-blocking/main.ts index 4b235d0..86238da 100644 --- a/examples/non-blocking/main.ts +++ b/examples/non-blocking/main.ts @@ -16,12 +16,13 @@ const interval = setInterval(() => { console.log('Computing fibonacci(42) on a worker pool...'); console.log('Meanwhile, the main thread keeps ticking:\n'); -const run = pool(2); -const start = performance.now(); -const [a, b] = await Promise.all([run(fibonacci(42)), run(fibonacci(41))]); -const elapsed = (performance.now() - start).toFixed(0); -run[Symbol.dispose](); +{ + using run = pool(2); + const start = performance.now(); + const [a, b] = await Promise.all([run(fibonacci(42)), run(fibonacci(41))]); + const elapsed = (performance.now() - start).toFixed(0); -clearInterval(interval); -console.log(`\n\nResults: fib(42)=${a}, fib(41)=${b}`); -console.log(`Computed in ${elapsed}ms with ${ticks} main-thread ticks (not blocked!)`); + clearInterval(interval); + console.log(`\n\nResults: fib(42)=${a}, fib(41)=${b}`); + console.log(`Computed in ${elapsed}ms with ${ticks} main-thread ticks (not blocked!)`); +} diff --git a/examples/parallel-batch/main.ts b/examples/parallel-batch/main.ts index 1456083..f148162 100644 --- a/examples/parallel-batch/main.ts +++ b/examples/parallel-batch/main.ts @@ -19,12 +19,14 @@ const seqTime = (performance.now() - seqStart).toFixed(0); console.log(` ${items.length} items in ${seqTime}ms\n`); // Parallel: distribute across a pool of 4 workers +let parTime: string; console.log('Parallel (worker pool, 4 workers)...'); -const run = pool(4); -const parStart = performance.now(); -const parResults = await Promise.all(items.map((item) => run(heavyWork(item)))); -const parTime = (performance.now() - parStart).toFixed(0); -run[Symbol.dispose](); -console.log(` ${items.length} items in ${parTime}ms\n`); +{ + using run = pool(4); + const parStart = performance.now(); + const parResults = await Promise.all(items.map((item) => run(heavyWork(item)))); + parTime = (performance.now() - parStart).toFixed(0); + console.log(` ${items.length} items in ${parTime}ms\n`); +} console.log(`Speedup: ~${(Number(seqTime) / Number(parTime)).toFixed(1)}x`); -- 2.51.2