function defineWorkerTask
Since 0.1.0
defineWorkerTask<TInput, TOutput>(fn: (input: TInput) => TOutput | Promise<TOutput>): void

Registers this module's task handler. Call once, at module top level, in a module that the WorkerPoolPlugin executes:

Examples

Example 1

// tasks/resize-image.ts — runs on a worker thread
import { defineWorkerTask } from '@setu-ts/runtime/worker';

defineWorkerTask<Uint8Array, Uint8Array>(async (imageBytes) => {
  return await resize(imageBytes);
});

Inputs and outputs travel by structured clone: plain data only, no functions or class instances.

Type Parameters

TInput
TOutput

Parameters

fn: (input: TInput) => TOutput | Promise<TOutput>

The task handler; may be async

Return Type

void

Throws

Error

When called outside a worker

Usage

import { defineWorkerTask } from "runtime/src/worker/define-worker-task.ts";