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.

feat(serve): scaffold subpath + public types

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

+50 -1
+8 -1
package.json
··· 8 8 "homepage": "https://tangled.org/divy.zone/moroutine", 9 9 "license": "MIT", 10 10 "type": "module", 11 - "exports": "./src/index.ts", 11 + "exports": { 12 + ".": "./src/index.ts", 13 + "./serve": "./src/serve/index.ts" 14 + }, 12 15 "publishConfig": { 13 16 "exports": { 14 17 ".": { 15 18 "types": "./dist/index.d.ts", 16 19 "default": "./dist/index.js" 20 + }, 21 + "./serve": { 22 + "types": "./dist/serve/index.d.ts", 23 + "default": "./dist/serve/index.js" 17 24 } 18 25 } 19 26 },
+1
src/serve/index.ts
··· 1 + export type { ListenArgs, ListenOptions, Balance, ServerThreads, ServerThreadsOptions } from './types.ts';
+41
src/serve/types.ts
··· 1 + import type { Channel } from '../channel.ts'; 2 + import type { Tuple } from '../shared/tuple.ts'; 3 + import type { Int32Atomic } from '../shared/int32-atomic.ts'; 4 + import type { WorkerHandle } from '../runner.ts'; 5 + 6 + /** Worker-side options, configured on `serverThreads` and shipped via `ListenArgs`. */ 7 + export interface ListenOptions { 8 + /** Per-worker drain budget after the channel ends, in ms. Default 30_000. */ 9 + drainTimeout?: number; 10 + } 11 + 12 + /** 13 + * Opaque tuple passed from `serverThreads` to each worker's moroutine. 14 + * The shape may evolve; users only ever spread it into `listen()`. 15 + */ 16 + export type ListenArgs = readonly [ 17 + channel: Channel<number>, 18 + counters: Tuple<Int32Atomic[]>, 19 + slot: number, 20 + opts: Required<ListenOptions>, 21 + ]; 22 + 23 + /** Connection-routing strategy. Picks a worker index given a counter snapshot. */ 24 + export interface Balance { 25 + pick(counters: readonly number[]): number; 26 + } 27 + 28 + export interface ServerThreadsOptions { 29 + /** Routing strategy. Default: `leastConns()`. */ 30 + balance?: Balance; 31 + /** Options forwarded to each worker's `listen()` call. */ 32 + listen?: ListenOptions; 33 + /** Per-worker fd-channel buffer size. Default 64. */ 34 + highWaterMark?: number; 35 + } 36 + 37 + /** 38 + * Disposable bundle pairing each `WorkerHandle` with its opaque `ListenArgs` tuple. 39 + * Iterable / indexable / `.map`-able. 40 + */ 41 + export interface ServerThreads extends Disposable, ReadonlyArray<readonly [WorkerHandle, ListenArgs]> {}