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:
Example 1
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.