Skip to content
1.0 is out: what changed →

hybrid-compute · local, worker, remote

Keep the main thread free.
Run each task where it fits.

Register a task once and let runTask() send it to the main thread, a Web Worker or a remote service over HTTP or WebSocket. Your code stays the same; only the strategy changes.

compute.runTask('resizeImage', blob, 'local')
Frames
Main thread
runTask('resizeImage') blocks the main thread
Worker
idle
Remote
idle
Runs on
local main
Main thread
Blocked
Frames
Dropped
strategy 'local', and the local backend can run it
runs on the main thread
Illustrative timeline, not a measurement.

Packages

Use core with any mix of the three backends.

PackageRuns onWhat it does
@hybrid-compute/coreanywhereThe orchestrator. Picks a backend for each task by strategy; with auto it falls back from worker to local to remote.
@hybrid-compute/localmainRuns registered tasks on the main thread. The right place for small, cheap work.
@hybrid-compute/workerWeb WorkerRuns tasks in a Web Worker, so heavy work never blocks rendering or input.
@hybrid-compute/remoteremote serviceSends tasks to a service over fetch or WebSocket, as JSON messages.

One call, any backend

Change the strategy, not the code.

// app.ts
const compute = createHybridCompute({ local, worker, remote });

await compute.runTask('resizeImage', blob);            // auto: worker, local, then remote
await compute.runTask('resizeImage', blob, 'worker');  // always off the main thread
await compute.runTask('summarise', text, 'remote');  // on your server

Why route tasks

A UI that never stutters

Parse, resize and transform in a worker; keep the main thread for input and rendering.

Data that stays on the device

Run sensitive steps locally and send only what a remote service really needs.

Works offline

Prefer local and worker backends, and reach for remote only when it is there.