Skip to content

Documentation / @hybrid-compute/worker / createThreadedCompute

Function: createThreadedCompute() ​

ts
function createThreadedCompute(
  options: ThreadedComputeOptionsInterface
): ThreadedCompute;

Defined in: packages/worker/src/index.ts:434

Creates a ThreadedCompute backend.

Parameters ​

options ​

ThreadedComputeOptionsInterface

The worker script (url or createWorker), the tasks it can run and, optionally, a timeout.

Returns ​

ThreadedCompute

A new ThreadedCompute instance.

Throws ​

For a missing or wrongly typed option.

Throws ​

For a negative timeout.

Example ​

ts
const backend = createThreadedCompute({
  createWorker: () =>
    new Worker(new URL('./resize.worker.ts', import.meta.url), {
      type: 'module'
    }),
  canRunTasks: ['resizeImage']
});