Offload functions to worker threads with shared memory primitives for Node.js.
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: document async dispose and run.signal in README

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+25
+25
README.md
··· 66 66 } 67 67 ``` 68 68 69 + #### Graceful Shutdown 70 + 71 + Use `await using` for graceful async shutdown. The pool exposes a `signal` that fires when disposal begins — thread it into tasks for cooperative cancellation. 72 + 73 + ```ts 74 + { 75 + await using run = workers(4); 76 + 77 + run(longTask(run.signal)); // task can react to abort 78 + run(otherTask()); // runs to completion 79 + } 80 + // signal fired, waited for both tasks, then workers terminated 81 + ``` 82 + 83 + Use `using` (without `await`) for immediate termination, same as before. 84 + 85 + A `shutdownTimeout` option force-terminates workers if graceful shutdown takes too long: 86 + 87 + ```ts 88 + { 89 + await using run = workers(4, { shutdownTimeout: 5000 }); 90 + // ... 91 + } 92 + ``` 93 + 69 94 ### Dedicated Workers 70 95 71 96 Awaiting a task directly (without a pool) runs it on a dedicated worker thread, one per moroutine function.