vortex

1. The interface vortex matches

@avarok/vortex 0.1.0 · Updated

1.1 Pinned reference

vortex matches piscina 5.3.2 (npm latest on 2026-11-27; tag v5.3.2, commit 6c7e54630a8c28a96ce5c0625b463d849d21171c; engines.node >= 20). Source of truth for this chapter is that tag's src/ and the published dist/*.d.ts of the npm tarball, read without running any install script.

Not matched (yet): the 6.0.0-rc.5 line. Its delta, read from piscina master (1afb9ca), is: recordTiming and workerHistogram removed, the histogram getter removed, a channels static and six diagnostics_channel message types added (PiscinaTaskSubmitMessage, …TaskStart…, …TaskDone…, …NewWorker…, …EvictWorker…, …Drain…), Node >= 22. Supporting 6.x later is an additive layer (section 5, phase 6).

piscina master also carries about fifteen bug fixes made after 5.3.2 (e.g. "reject run() after the pool has been closed or destroyed", "enforce maxQueue for tasks submitted with an AbortSignal", "let close() finish when the last queued task is aborted", "keep replacing crashed workers after aborting a task on a starting worker"). Policy: vortex follows the fixed behaviour wherever no 5.3.2 test pins the buggy one, and lists each such divergence in docs/COMPAT.md (phase 2).

1.2 Module exports

CommonJS module.exports = Piscina (the class is the module), plus ESM wrapper re-exporting: default, Piscina, ArrayTaskQueue, FixedQueue, isWorkerThread, move, queueOptionsSymbol, transferableSymbol, valueSymbol, version, workerData. Type-only exports: PiscinaTask, TaskQueue. Package exports map: types / import (esm wrapper) / require (cjs main).

Three tests also deep-import internals: dist/symbols (kQueueOptions), dist/common (getAvailableParallelism, isMovable, markMovable…), dist/worker_pool (the PiscinaWorker type). vortex ships the same paths as thin re-exports so those tests run unmodified; they are not promised as public API.

1.3 Constructor options (new Piscina(options?))

Option Type Default (5.3.2) Validation error
filename string | null (path or file: URL) null TypeError options.filename must be a string or null
name string 'default' TypeError …name must be a string or null
minThreads number ≥ 0 max(floor(P/2),1) TypeError non-negative integer
maxThreads number ≥ 1 P * 1.5 (not floored) TypeError positive integer
(both given, min > max) RangeError …must not conflict
idleTimeout number ≥ 0, Infinity = never 0 TypeError
maxQueue number ≥ 0 or 'auto' (= maxThreads ** 2) Infinity TypeError
concurrentTasksPerWorker number ≥ 1 1 TypeError
atomics 'sync' | 'async' | 'disabled' 'sync' TypeError
resourceLimits object (Worker resourceLimits) none TypeError
argv, execArgv string[] none none
env Worker env (incl. SHARE_ENV) none none
workerData any (cloned once per worker) none none
taskQueue object with size, shift, remove, push (unshift optional) FixedQueue (internal); ArrayTaskQueue in options view TypeError
niceIncrement number (≥ 0 off Windows; uses optional @napi-rs/nice) 0 TypeError
trackUnmanagedFds boolean true TypeError
closeTimeout number ≥ 0 ms 30000 TypeError
recordTiming boolean true none
stricterFIFO boolean false TypeError
loadBalancer (task: PiscinaTask, workers: PiscinaWorker[]) => PiscinaWorker | null LeastBusyBalancer({maximumUsage: concurrentTasksPerWorker}) TypeError
workerHistogram boolean false TypeError

P = os.availableParallelism(). Clamping quirks to reproduce: if only maxThreads is given and minThreads >= maxThreads, minThreads = maxThreads; if only minThreads is given and maxThreads <= minThreads, maxThreads = minThreads. Options are copied into a null-prototype object; unknown keys are ignored.

PCND note. A drop-in replacement must reproduce these defaults, so they cannot be removed. vortex keeps them in exactly one module (js/defaults.ts) that is the compatibility specification itself, with a test asserting each value against this table. Nothing else in vortex may default anything. The owner approved this exception (Q5, 2026-11-27).

1.4 run(task, options?) → Promise<R>

Options (null-prototype copy): transferList?: TransferListItem[], filename?: string|null, name?: string|null, signal?: AbortSignal | EventEmitter-with-'abort' | null. Errors are returned as rejected promises, never thrown: options must be an object, transferList argument must be an Array, filename argument must be a string, name argument must be a string, signal argument must be an object, filename must be provided to run() or in options object.

Semantics to reproduce:

1.5 close({force?}), destroy(), disposal

1.6 Events (EventEmitter)

'workerCreate'(PiscinaWorker) (for initial workers: next microtask, so listeners attached after the constructor see it), 'workerDestroy'(PiscinaWorker), 'message'(any) (anything a worker posts on parentPort other than the internal ready message), 'error'(Error) (worker error with no task to blame; close timeout; unexpected response), 'drain', 'needsDrain' (both emitted in a microtask when currentUsage crosses maxThreads * concurrentTasksPerWorker), 'close'.

1.7 Instance properties (all read-only getters)

maxThreads, minThreads, options (filled options, null-prototype), threads: Worker[] (the real worker_threads.Worker objects), idleThreads, queueSize (= max(queue + skipQueue − pendingCapacity, 0)), completed, histogram ({runTime, waitTime, resetRunTime(), resetWaitTime()}; summaries have average, mean, stddev, min, max, p0_001, p0_01, p0_1, p1, p2_5, p10, p25, p50, p75, p90, p97_5, p99, p99_9, p99_99, p99_999, recorded as µs integers (min 1) and reported in ms), utilization (mean_runtime_ms × count / (duration × maxThreads), 0 without timing), duration (ms since construction), needsDrain.

PiscinaWorker (given to balancers and events): id (= threadId), currentUsage, isRunningAbortableTask, histogram (summary or null), terminating, destroyed, plus an internal symbol link. PiscinaTask (to balancers and queues): taskId, filename, name, created, isAbortable, [kQueueOptions].

Note: piscina's README still documents top-level runTime/waitTime; the 5.x code moved them under histogram. vortex follows the code.

1.8 Statics

Piscina.isWorkerThread, Piscina.workerData, Piscina.version (vortex reports its own version, plus a vortex static compatibleWith = '5.3.2'; Q6), Piscina.Piscina, Piscina.FixedQueue, Piscina.ArrayTaskQueue, Piscina.move(value) (wraps ArrayBuffer / ArrayBufferView / MessagePort / Transferable in a movable marker; primitives returned as is), transferableSymbol, valueSymbol, queueOptionsSymbol (symbols must be the same symbol objects across the main and worker module instances of the package, which piscina gets by plain module identity).

1.9 Worker-side conventions

1.10 Error messages

Terminating worker thread, filename must be provided to run() or in options object, Task queue is at limit, No task queue available and all Workers are busy, Close operation timed out, worker exited with code: N, The task has been aborted (AbortError; the reason, e.g. 'pool is closed', is its cause). Tests compare these strings, so they are part of the contract and live in one module (js/errors.ts).