ZOYKUHot Board

mimiMonads/knittingDokumentacja

mimiMonads/knitting open-source repository on GitHub

Uwaga dotycząca języka:Brak zlokalizowanej dokumentacji. Wyświetlana jest oficjalna wersja oryginalna w języku angielskim.
Szybka instalacja
git clone https://github.com/mimiMonads/knitting.git

knitting

JSR Version npm Version Tests Coverage Workflow License

Knitting is a worker pool for Node.js, Deno, and Bun, with a focus on HTTP servers and request offloading. It runs JavaScript and TypeScript functions in threads or separate processes. Calls use shared memory, and results come back as promises.

Website: js.knitting.run

For agents, the website provides a compact documentation map in llms.txt and full documentation in llms-full.txt.

Knitting specializes in:

  • Offloading CPU-heavy work from HTTP request handlers.
  • Parsing and validating request bodies.
  • Server-side rendering and compression.
  • Sharing large buffers between workers.
  • Running tasks across threads and processes.

Documentation · API guide · Source map · Discord

Install

npm install knitting

For Deno, use deno add --npm knitting.

Example

Save this as example.mjs:

import { createPool, isMain } from "knitting";

export const square = (value) => value * value;
export const greet = (name) => `hello ${name}`;

if (isMain) {
  const pool = createPool({ threads: 2 })({ square, greet });

  try {
    const [four, message] = await Promise.all([
      pool.call.square(2),
      pool.call.greet("knitting"),
    ]);
    console.log({ four, message });
  } finally {
    await pool.shutdown();
  }
}

Run it with Node.js, Bun, or Deno:

node example.mjs
bun example.mjs
deno run -A example.mjs

The result is { four: 4, message: "hello knitting" }.

Export your functions so workers can load them. Keep pool creation inside if (isMain) so workers don't create pools of their own. Call shutdown() when you're done; finally makes sure it also runs if a task fails.

This example works on Node.js 22. Runtimes with await using can use it for cleanup instead; see pool cleanup. Deno's -A grants all permissions for the example.

Features

  • Typed function calls across threads and processes.
  • Timeouts and cancellation.
  • JSON, typed arrays, and shared buffers.
  • Work stealing and scheduling options.
  • Browser support for pages with cross-origin isolation enabled.

See the API guide for configuration and experimental backends.

Runtime support

Knitting requires Node.js 22+, Deno 2+, or Bun 1+. The test workflow covers Linux, macOS, and Windows; check it for tested versions and results.

Node.js native addons are packaged for 22 and 24 on Linux x64, macOS x64/arm64, and Windows x64. Node.js 26 has an experimental FFI backend. See native support for details.

Permissions depend on the runtime and worker type. Read the permission guide when setting up process isolation.

Benchmarks

Shared memory can reduce the cost of sending work to a worker. How much it helps depends on the task, payload, runtime, and pool settings.

./run.sh --json --bench=doorbell --runtime=node

See the benchmarks for commands, measurements, and reports. Compare repeated runs with the same settings, and test your own workload before drawing conclusions.

Development

Bun runs the build scripts. Install Node.js and Deno too if you want to test all three runtimes.

bun install --frozen-lockfile
bun run build
npm run test:node
npm run test:bun
npm run test:deno

See Contributing for native builds, browser tests, and pull requests. Report security issues using the security policy.

License

Apache-2.0.

Kopia dokumentacji z oficjalnego repozytorium GitHub · Zobacz na GitHubie
Data migawki: 2026-11-08