useWebWorker

Simple Web Workers registration and communication.

Try out the high-level useWebWorkerFn

Usage

import { useWebWorker } from 'vue-use-web'

const { data, post, terminate } = 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
MethodSignatureDescription
post(data: any) => voidSends data to the worker thread.
terminate() => voidStops and terminates the worker.

Type Declarations

/**
 * Simple Web Workers registration and communication.
 *
 * @see /useWebWorker
 * @param url
 * @param workerOptions
 * @param options
 */
export declare function useWebWorker(
  url: string,
  workerOptions?: WorkerOptions,
  options?: ConfigurableWindow
): {
  data: Ref<any>
  post: {
    (message: any, transfer: Transferable[]): void
    (message: any, options?: PostMessageOptions | undefined): void
  }
  terminate: () => void
  worker: Ref<Worker | undefined>
}
export declare type UseWebWorkerReturn = ReturnType<typeof useWebWorker>

Source

SourceDocs