Skip to content
familiar logoFamiliarWorkers
Typed ES module Worker pools with cancellation, priority scheduling, streaming, and test utilities.
Version
v2.0.1
Size
3.8 KB gzip
Browser
createWorkercreateStreamWorkerbatchcreateTaskGroupFamiliarError View all 10 exports

Why Familiar?

Raw workers force every application to maintain its own message contract, lifecycle, cancellation, and pool scheduler. Familiar provides those boundaries while keeping worker code in normal typed ES modules.

ts
// Before
const worker = new Worker(new URL('./sum.worker.ts', import.meta.url), { type: 'module' });
worker.postMessage([1, 2, 3]);

// After
const pool = createWorker<number[], number>(new URL('./sum.worker.ts', import.meta.url));
await pool.run([1, 2, 3]);
FeatureFamiliarRaw WorkerComlink
Bundle size3.8 KBbuilt-in~2 kB
Module-worker contractmanual
Pool scheduling
AbortSignal cancellationmanualmanual
Versioned protocolimplementation-specific
Zero dependencies

Use Familiar when worker jobs need bounded concurrency, typed errors, cancellation, or queue policy.

Consider raw Worker when one isolated worker and custom messaging are enough.

Installation

sh
pnpm add @vielzeug/familiar
sh
npm install @vielzeug/familiar
sh
yarn add @vielzeug/familiar

Quick Start

Register task logic inside a worker module.

ts
// double.worker.ts
import { exposeTask } from '@vielzeug/familiar/protocol';

exposeTask((value: number) => value * 2);

Create pool from module URL and dispose it after use.

ts
import { createWorker } from '@vielzeug/familiar';

const worker = createWorker<number, number>(new URL('./double.worker.ts', import.meta.url));

try {
  console.log(await worker.run(21));
} finally {
  worker.dispose();
}

Features

  • createWorker() — versioned task protocol over ES module workers
  • createStreamWorker() — stream-only worker capability
  • run() — priority scheduling, transferables, timeout, and cancellation
  • batch() — ordered task composition
  • createTaskGroup() — shared cancellation and settlement tracking
  • stats — active, queued, completed, and failed counters
  • createTestWorker() — faithful in-process task-pool testing
  • dispose() and drain() — immediate or draining teardown, with using support

Documentation

See Also

  • Arsenal — async helpers for application coordination.
  • Ripple — expose worker results through reactive state.
  • Herald — publish application events after worker jobs settle.