useWorkerFunction

A hook that exec the function in worker.

Implementation is original ported from useWorker

Examples

Basic Usage

API

const { callWokerFn, status, worker, killWorker } = useWorkerFunction(
  fn,
  Options?,
);

Result

ValueTypeDescription
workerFn(...workerArgs: Parameters<T>) => Promise<ReturnType<T>>The function that allows you to run fn with web worker
statusRef<WORKER_STATUS>The status of workerFn
killWorkerFunctionThe function that allows killing the worker
workerRef<WorkerWithURL>The worker

Params

ValueTypeDescription
fnFunctionThe pure function to run with web workers
optionsObjectThe object containing the options of the worker

Options

ValueTypeDefaultDescription
timeoutNumberundefinedThe number of milliseconds before killing the worker
remoteDependenciesArray of String[]An array that contains the remote dependencies needed to run the worker
autoTerminateBooleantrueKill the worker once it's done (success or error)
transferableString'auto'Enable Transferable Objects, to disable it set transferable: 'none'

最近更新: