useWebWorker
Simple Web Workers registration and communication.
Related Functions
Try out the high-level useWebWorkerFn
Usage
import { useWebWorker } from '@vueuse/core'
const { data, post, terminate } = useWebWorker('/path/to/worker.js')
import { useWebWorker } from '@vueuse/core'
const { data, post, terminate } = useWebWorker('/path/to/worker.js')
State | Type | Description |
---|---|---|
data | Ref<any> | Reference to the latest data received via the worker, can be watched to respond to incoming messages |
Method | Signature | Description |
---|---|---|
post | (data: any) => void | Sends data to the worker thread. |
terminate | () => void | Stops and terminates the worker. |
Type Declarations
export interface UseWebWorkerReturn<Data = any> {
data: Ref<Data>
post: typeof Worker.prototype["postMessage"]
terminate: () => void
worker: Ref<Worker | undefined>
}
/**
* Simple Web Workers registration and communication.
*
* @see https://vueuse.org/useWebWorker
* @param url
* @param workerOptions
* @param options
*/
export declare function useWebWorker<Data = any>(
url: string,
workerOptions?: WorkerOptions,
options?: ConfigurableWindow
): UseWebWorkerReturn<Data>
export interface UseWebWorkerReturn<Data = any> {
data: Ref<Data>
post: typeof Worker.prototype["postMessage"]
terminate: () => void
worker: Ref<Worker | undefined>
}
/**
* Simple Web Workers registration and communication.
*
* @see https://vueuse.org/useWebWorker
* @param url
* @param workerOptions
* @param options
*/
export declare function useWebWorker<Data = any>(
url: string,
workerOptions?: WorkerOptions,
options?: ConfigurableWindow
): UseWebWorkerReturn<Data>
Source
Contributors
Anthony Fu
Antério Vieira
karma
Shinigami
Mario Kolli
Shinigami
wheat
Alex Kozack
userquin