fn
useWebWorker
v0.0.15testeddemoSimple Web Worker communication with reactive incoming data and automatic teardown
Examples
ts
const { data, post, terminate } = useWebWorker('/worker.js');
post({ type: 'start' });
watch(data, value => console.log(value));ts
const { data } = useWebWorker(() => new Worker(new URL('./worker.ts', globalThis._importMeta_.url)));Demo
Loading demo…
Signature
ts
export function useWebWorker<Data = any>(
source: WebWorkerSource,
options: UseWebWorkerOptions ={ ... }Type Parameters
Data= anyParameters
| Parameter | Type | Description |
|---|---|---|
source | WebWorkerSource | A `Worker` instance, a script URL/string, or a factory returning a `Worker` |
options? | UseWebWorkerOptions | Worker constructor options and message/error hooks |
Returns
UseWebWorkerReturn<Data>`{ data, post, terminate, worker, isSupported }`