Concurrency runtime for JavaScript
Move JavaScript
off the main thread.
npm install knittingNode · Deno · Bunimport { serve } from "@hono/node-server";
import { Hono } from "hono";
import { createPool, isMain } from "knitting";
export const double = (n: number) => n * 2;
if (isMain) {
const pool = createPool({
threads: 1,
})({ double });
const app = new Hono().get("/", async (c) =>
c.json({ result: await pool.call.double(21) })
);
serve({ fetch: app.fetch, port: 3000 });
} ❯ bun run server.ts
{ result: 42 }
host bun · main thread
await pool.call.double(21)shared memory
same process, shared memory
No runtime dependencies
Typed calls
Threads or processes
Apache-2.0
In a busy server
Keep fast routes fast.
Move React rendering and JWT signing to one worker. Keep lightweight routes like /ping on the main thread.
Hono · 1 worker · 15-second runs. Results vary by workload.
Request flow
BeforeResponses →
Main thread8 waiting → running
/sign/ping/ping/ping/ping/render/sign/ping /render With one workerResponses →
Main thread2 waiting → running
/ping/ping /ping Worker3 waiting → running
/sign/render/sign /render /ping response time p99
16.93 msBefore
2.31 msWith one worker
Animation is illustrative.
Work stealing
Finish a task. Pick up another.
12 waiting
Worker 1Ready
Queue10 waiting
#01#03#05#06#07#08#09#10#11#12
—
0 done
Worker 2Ready
Queue2 waiting
#02#04
—
0 done
0 completed
Quick start
Run a function in a worker.
main.tsTypeScript
import { serve } from "@hono/node-server";import { brotliCompressSync } from "node:zlib";import { Hono } from "hono";import { createPool, isMain } from "knitting";
export const compress = (html: string) => brotliCompressSync(html).byteLength;
if (isMain) { const pool = createPool({ threads: 1 })({ compress }); const app = new Hono().get("/", async (c) => { const html = c.req.query("html") ?? "<h1>Hello from Hono</h1>"; return c.json({ compressedBytes: await pool.call.compress(html) }); }); serve({ fetch: app.fetch, port: 3000 });}A runtime around your workers.
✓Built in◐Manual or limited×Not included
| Feature | Node.js workers | Piscina | Knitting |
|---|---|---|---|
| Task API | Manual or limited: Messages + handlers | Built in: run(task) | Built in: Typed function calls |
| Worker pools | Manual or limited: Build your own | Built in: Managed pool | Built in: createPool() |
| Scheduling | Manual or limited: Your queue | Built in: Host task queue | Built in: Native stealing¹ |
| Task cancellation | Manual or limited: Custom protocol | Built in: AbortSignal; ends worker | Built in: Cooperative shared signal |
| Soft task timeouts | Manual or limited: Your timer | Manual or limited: Your timer | Built in: timeout option⁴ |
| Hard wall-clock deadlines | Manual or limited: Timer + terminate | Manual or limited: Timed AbortSignal | Built in: hardTimeoutMs³ |
| Shared-memory task transport | Manual or limited: Shared buffers | Manual or limited: Atomics + messages | Built in: Shared mailboxes |
| Process workers | Not included: Separate API² | Not included: Threads only | Built in: Same pool API |
| Runtime support | Manual or limited: Node.js | Manual or limited: Node.js | Built in: Node · Bun · Deno |
Examples
Rendering, hashing, and compression.
See how it’s tested.
Tests cover shared memory, cancellation, timeouts, and worker failures.
Pick one slow function.
Knitting ships machine-readable docs at /llms.txt and /llms-full.txt. Read them before generating code.
Workers re-import the task module, including its top-level imports. Keep task modules lean, export every task, and use importTask when code should load only inside the worker.

