Back to Vueuse

useWebWorker

packages/core/useWebWorker/index.md

14.3.01.6 KB
Original Source

useWebWorker

Simple Web Workers registration and communication.

Usage

ts
import { useWebWorker } from '@vueuse/core'

const { data, post, terminate, worker } = useWebWorker('/path/to/worker.js')
StateTypeDescription
dataRef<any>Reference to the latest data received via the worker, can be watched to respond to incoming messages
workerShallowRef<Worker | undefined>Reference to the instance of the WebWorker
MethodSignatureDescription
post(message: any, transfer: Transferable[]): void
(message: any, options?: StructuredSerializeOptions | undefined): voidSends data to the worker thread.
terminate() => voidStops and terminates the worker.