threadsx
Make web workers & worker threads as simple as a function call.
Maintained, modernized fork of threads.js
$npm install threadsx
Transparent API
Write once, run everywhere
Call workers transparently and await results — in web workers and node worker threads alike.
import { spawn, Thread, Worker } from "threadsx"
const auth = await spawn(new Worker("./workers/auth"))
const hashed = await auth.hashPassword("Super secret", "1234")
console.log("Hashed password:", hashed)
await Thread.terminate(auth)import sha256 from "js-sha256"
import { expose } from "threadsx/worker"
expose({
hashPassword(password, salt) {
return sha256(password + salt)
}
})Built for today
Modern features
Designed for modern JavaScript and TypeScript code.
Async functions & observables
Built on functional paradigms and modern APIs, threadsx makes it easy to write clear, declarative code.
Statically typed
Completely written in TypeScript — a robust code base that always ships up-to-date types out of the box.
Bundler-native
Works out of the box with webpack 5, Vite, esbuild and rollup via new Worker(new URL(…, import.meta.url)) — no plugin required.
Use cases
Versatile by design
Web workers and worker threads turn out to be pretty handy.
Speed up CPU-bound code
Outsource calculation-intensive work to one or many workers to improve performance drastically.
Thread pools
Manage bulk tasks with a pool that dispatches work to workers in a controlled, predictable way.
Smooth UI
Offload business logic from the main thread — where rendering happens — and keep a buttery 60 FPS.
Sandbox sensitive code
Shield security-relevant logic from the rest of the app by isolating it inside a dedicated worker.
Runs anywhere
Supported platforms
An abstraction layer over the different worker implementations.
Every desktop OS
Continuously tested on Linux, macOS and Windows in CI.