Registry / devops / ts-task-queue

ts-task-queue

JSON →
library2.0.0jsnpmunverified

ts-task-queue is a TypeScript library for creating and managing task queues with a pool of worker threads. Version 2.0.0 provides a simple API based on the `Queue` class, supporting typed task input/output, customizable worker count (default 4), error handling, and multiple queues. It leverages Node.js worker threads for parallel execution and requires the `isMainThread()` guard to separate main and worker code. Unlike generic job queues, it focuses on lightweight in-process threading with TypeScript-first design. The package ships with TypeScript types and is ESM-compatible.

devops
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.

Default import is not supported. Must use named import.

import { Queue } from 'ts-task-queue'

Using CommonJS `require` returns an object with named exports; must destructure: `const { Queue } = require('ts-task-queue')`.

import { Queue } from 'ts-task-queue'

Aliasing is valid but unnecessary.

import { Queue } from 'ts-task-queue'

Creates a typed queue for adding two numbers, pushes a task, and logs the result. Demonstrates Queue instantiation, callback, and isMainThread() guard.

import { Queue } from 'ts-task-queue'; interface AddTask { a: number; b: number; } const addQueue = new Queue<AddTask, number>({ name: 'add-queue', callback: async (task: AddTask) => task.a + task.b, }); if (addQueue.isMainThread()) { (async () => { const sum = await addQueue.await({ data: { a: 4, b: 8 } }); console.log('Sum is', sum); })(); }
Debug
Known footguns
gotchaWorkers execute the same module; application code must be guarded with `isMainThread()` to avoid running on workers.
gotchaThe callback must be an async function. Non-async callbacks will cause runtime errors.
gotchaEach queue requires a unique `name`. Duplicate names may cause worker conflicts.
gotchaWhen using `ts-node`, a JavaScript entry-point file is required for workers. Direct TypeScript execution fails.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
ahrefsbot
1
Resources