Skip to content

useWebWorker

Category
Export Size
325 B
Last Changed
3 months ago
Related

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): void
Sends data to the worker thread.
terminate() => voidStops and terminates the worker.

Type Declarations

ts
type 
PostMessage
= (typeof
Worker
.
prototype
)["postMessage"]
export interface
UseWebWorkerReturn
<
Data
= any> {
data
:
Ref
<
Data
>
post
:
PostMessage
terminate
: () => void
worker
:
ShallowRef
<Worker | undefined>
} type
WorkerFn
= (...
args
: unknown[]) => Worker
/** * Simple Web Workers registration and communication. * * @see https://vueuse.org/useWebWorker * @param url * @param workerOptions * @param options */ export declare function
useWebWorker
<
T
= any>(
url
: string,
workerOptions
?: WorkerOptions,
options
?:
ConfigurableWindow
,
):
UseWebWorkerReturn
<
T
>
/** * Simple Web Workers registration and communication. * * @see https://vueuse.org/useWebWorker */ export declare function
useWebWorker
<
T
= any>(
worker
: Worker |
WorkerFn
,
):
UseWebWorkerReturn
<
T
>

Source

SourceDocs

Contributors

Anthony Fu
Anthony Fu
Antério Vieira
SerKo
René Hellenes
Yasser Lahbibi
DarknessChaser
Young
karma
Shinigami
Mario Kolli
Shinigami
wheat
Alex Kozack
userquin

Changelog

v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.2.0 on
5988f - fix: add web worker transferable option (#3123)

Released under the MIT License.

Black Friday Super Early Bird
Get 60% off + 9 premium Vue mastery bonuses
The most generous offer we’ve ever made
Buy Now
TIME LIMITED OFFER