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.

chore: version 1.0.0

+57 -74
-10
.changeset/async-worker-cleanup.md
··· 1 - --- 2 - 'moroutine': minor 3 - --- 4 - 5 - Graceful async worker pool shutdown 6 - 7 - - `await using run = workers(4)` waits for in-flight tasks to settle before terminating workers 8 - - `run.signal` is an `AbortSignal` that fires when the pool starts disposing — thread it into tasks for cooperative cancellation 9 - - `workers(size, { shutdownTimeout: ms })` force-terminates workers if graceful shutdown exceeds the timeout 10 - - Existing `using run` (sync dispose) still terminates immediately
-20
.changeset/error-stack-traces.md
··· 1 - --- 2 - 'moroutine': minor 3 - --- 4 - 5 - Include main-thread call site in error stack traces 6 - 7 - Errors thrown during task dispatch now have stack traces that show where `run()`, `exec()`, or `await task` was called. The original worker-side error is preserved as `err.cause` with its own stack pointing to the moroutine source. 8 - 9 - ``` 10 - Error: boom 11 - at trackValue (worker-pool.ts:52:15) 12 - at async loadUser (user-code.ts:7:3) 13 - at async main (user-code.ts:11:3) { 14 - [cause]: Error: boom 15 - at fixtures/math.ts:6:9 // original throw site on the worker 16 - at MessagePort.<anonymous> (worker-entry.ts:173:25) 17 - } 18 - ``` 19 - 20 - Built-in error subclass identity (`TypeError`, `RangeError`, etc.) is preserved on the outer wrapper.
-7
.changeset/error-transfer.md
··· 1 - --- 2 - 'moroutine': minor 3 - --- 4 - 5 - Preserve error details across worker boundary 6 - 7 - Errors thrown in moroutines now transfer with `message`, `stack`, `cause`, and built-in subclass identity (`TypeError`, `RangeError`, etc.) preserved via structured clone. Previously only the message string was kept.
-9
.changeset/load-balancing.md
··· 1 - --- 2 - 'moroutine': minor 3 - --- 4 - 5 - Configurable load balancing for worker pools 6 - 7 - - `workers(size, { balance: leastBusy() })` routes tasks to the worker with the fewest in-flight tasks 8 - - `roundRobin()` cycles through workers in order (default, same as before) 9 - - Custom balancers implement `Balancer.select(workers, task)` for full control over scheduling
-10
.changeset/per-worker-dispatch.md
··· 1 - --- 2 - 'moroutine': minor 3 - --- 4 - 5 - Per-worker dispatch with `assign()` and `run.workers` 6 - 7 - - `run.workers` exposes a read-only array of `WorkerHandle`s, one per pool worker 8 - - `assign(worker, task)` returns a copy of the task pinned to a specific worker 9 - - `worker.exec(task)` dispatches directly to a specific worker 10 - - Channel fan-out no longer requires knowing the worker count
-7
.changeset/pool-worker-ref.md
··· 1 - --- 2 - 'moroutine': patch 3 - --- 4 - 5 - Fix pool workers exiting early with top-level await 6 - 7 - Pool workers are now ref'd for the lifetime of the pool, preventing the Node.js event loop from exiting prematurely when using `using run = workers()` with top-level `await`. Dedicated workers continue to ref only while tasks are in-flight.
-10
.changeset/task-type-refactor.md
··· 1 - --- 2 - 'moroutine': major 3 - --- 4 - 5 - Unify Task and StreamTask under a single `Task<T>` type 6 - 7 - - `Task<T>` is `PromiseLike<T>` for value tasks, `AsyncIterable<T>` for streaming tasks, or just the base dispatch shape when unparameterized 8 - - `Balancer.select()` receives `Task` instead of `Task<any> | StreamTask<any>` 9 - - `Arg<T>` simplifies to `T | Task<T>` 10 - - Classes renamed to `PromiseLikeTask<T>` and `AsyncIterableTask<T>` (internal, prefer `Task<T>` in type annotations)
+56
CHANGELOG.md
··· 1 1 # moroutine 2 2 3 + ## 1.0.0 4 + 5 + ### Major Changes 6 + 7 + - e46aca0: Unify Task and StreamTask under a single `Task<T>` type 8 + - `Task<T>` is `PromiseLike<T>` for value tasks, `AsyncIterable<T>` for streaming tasks, or just the base dispatch shape when unparameterized 9 + - `Balancer.select()` receives `Task` instead of `Task<any> | StreamTask<any>` 10 + - `Arg<T>` simplifies to `T | Task<T>` 11 + - Classes renamed to `PromiseLikeTask<T>` and `AsyncIterableTask<T>` (internal, prefer `Task<T>` in type annotations) 12 + 13 + ### Minor Changes 14 + 15 + - 9ab6016: Graceful async worker pool shutdown 16 + - `await using run = workers(4)` waits for in-flight tasks to settle before terminating workers 17 + - `run.signal` is an `AbortSignal` that fires when the pool starts disposing — thread it into tasks for cooperative cancellation 18 + - `workers(size, { shutdownTimeout: ms })` force-terminates workers if graceful shutdown exceeds the timeout 19 + - Existing `using run` (sync dispose) still terminates immediately 20 + 21 + - 3612d52: Include main-thread call site in error stack traces 22 + 23 + Errors thrown during task dispatch now have stack traces that show where `run()`, `exec()`, or `await task` was called. The original worker-side error is preserved as `err.cause` with its own stack pointing to the moroutine source. 24 + 25 + ``` 26 + Error: boom 27 + at trackValue (worker-pool.ts:52:15) 28 + at async loadUser (user-code.ts:7:3) 29 + at async main (user-code.ts:11:3) { 30 + [cause]: Error: boom 31 + at fixtures/math.ts:6:9 // original throw site on the worker 32 + at MessagePort.<anonymous> (worker-entry.ts:173:25) 33 + } 34 + ``` 35 + 36 + Built-in error subclass identity (`TypeError`, `RangeError`, etc.) is preserved on the outer wrapper. 37 + 38 + - 5137201: Preserve error details across worker boundary 39 + 40 + Errors thrown in moroutines now transfer with `message`, `stack`, `cause`, and built-in subclass identity (`TypeError`, `RangeError`, etc.) preserved via structured clone. Previously only the message string was kept. 41 + 42 + - d13cd40: Configurable load balancing for worker pools 43 + - `workers(size, { balance: leastBusy() })` routes tasks to the worker with the fewest in-flight tasks 44 + - `roundRobin()` cycles through workers in order (default, same as before) 45 + - Custom balancers implement `Balancer.select(workers, task)` for full control over scheduling 46 + 47 + - cdccfdb: Per-worker dispatch with `assign()` and `run.workers` 48 + - `run.workers` exposes a read-only array of `WorkerHandle`s, one per pool worker 49 + - `assign(worker, task)` returns a copy of the task pinned to a specific worker 50 + - `worker.exec(task)` dispatches directly to a specific worker 51 + - Channel fan-out no longer requires knowing the worker count 52 + 53 + ### Patch Changes 54 + 55 + - e2dabc1: Fix pool workers exiting early with top-level await 56 + 57 + Pool workers are now ref'd for the lifetime of the pool, preventing the Node.js event loop from exiting prematurely when using `using run = workers()` with top-level `await`. Dedicated workers continue to ref only while tasks are in-flight. 58 + 3 59 ## 0.1.1 4 60 5 61 ### Patch Changes
+1 -1
package.json
··· 1 1 { 2 2 "name": "moroutine", 3 - "version": "0.1.1", 3 + "version": "1.0.0", 4 4 "repository": { 5 5 "type": "git", 6 6 "url": "git@tangled.org:divy.zone/moroutine"