Registry / devops / ts-fork-queue

ts-fork-queue

JSON →
library0.1.34jsnpmunverified

A minimalistic Node.js fork queue that schedules enqueued tasks and runs them in separate child processes using child_process.fork(). Version 0.1.34 is the latest stable release, with no active release cadence. Key differentiators: TypeScript-first, configurable queue size and parallelism, polling-based scheduler. Limited to forking Node.js modules; tasks must self-terminate via process.exit().

npm install ts-fork-queue
INSTALL
IMPORT
SIG · TS-FORK-QUEUE
T
ts-fork-queue
devopsjavascriptv0.1.34
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ForkQueue
import { ForkQueue } from 'ts-fork-queue'
const ForkQueue = require('ts-fork-queue')
ESM named export. CommonJS require will not work because the package is ESM-only.
QueueFullError
import { QueueFullError } from 'ts-fork-queue'
Class thrown when enqueuing to a full queue.
InvalidConfigError
import { InvalidConfigError } from 'ts-fork-queue'
Class thrown when an invalid configuration object is passed to ForkQueue constructor.

Creates a ForkQueue with max 5 queued tasks and 2 parallel processes, starts the scheduler, and enqueues a task that forks a Node.js worker module.

import { ForkQueue } from 'ts-fork-queue'; import { resolve } from 'path'; const queue = new ForkQueue({ maxQueueSize: 5, maxParallelism: 2, pollingPeriodSeconds: 1 }); queue.start(); const task = { getCommand: () => resolve(__dirname, './worker.js'), getArgs: () => '--port=3000', getCwd: () => __dirname, toString: () => 'worker' }; try { queue.enqueue(task); } catch (err) { if (err instanceof (await import('ts-fork-queue')).QueueFullError) { console.error('Queue is full'); } } // Worker script (worker.js): process.exit(0) after work is done.
Debug
Known issues
gotchaTasks must call process.exit() to terminate; the queue does not kill child processes when the root process exits.
fix
Ensure each forked module calls process.exit() after completing its work, or the process will hang until the parent dies.
affects: >=0.1.0
gotchaenqueue() throws QueueFullError if the queue is at max capacity. The error is not returned, it must be caught with try/catch.
fix
Wrap enqueue() in a try-catch block to handle queue full conditions.
affects: >=0.1.0
gotchaConfiguration validation is strict; invalid values throw InvalidConfigError at construction time.
fix
Ensure maxQueueSize >= 1, maxParallelism >= 1, pollingPeriodSeconds > 0.
affects: >=0.1.0
gotchaPolling period uses seconds, not milliseconds. Setting pollingPeriodSeconds too low (<0.1) may cause high CPU usage.
fix
Use a reasonable polling interval, e.g. 2 seconds, to avoid excessive CPU load.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'ts-fork-queue'
Package not installed.
fix
npm install ts-fork-queue
ForkQueue is not a constructor
Using CommonJS require on an ESM-only package.
fix
Use import { ForkQueue } from 'ts-fork-queue' or enable ESM in your project.
TypeError: task.getCommand is not a function
Task object does not implement the required interface (missing getCommand, getArgs, getCwd, toString).
fix
Provide an object with all four methods returning strings.
Upgrade
Version history
0.1.34latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
ts-fork-queue — npm install ts-fork-queue · libregistry