Worker

open external class Worker(scriptURL: String, options: WorkerOptions = definedExternally) : EventTarget, AbstractWorker(source)

This Web Workers API interface represents a background task that can be easily created and can send messages back to its creator. Creating a worker is as simple as calling the Worker() constructor and specifying a script to be run in the worker thread.

MDN Reference

Constructors

Link copied to clipboard
constructor(scriptURL: URL, options: WorkerOptions = definedExternally)
constructor(scriptURL: String, options: WorkerOptions = definedExternally)

Functions

Link copied to clipboard
Link copied to clipboard
fun postMessage(message: Any?, transfer: ReadonlyArray<Transferable>)

Clones message and transmits it to worker's global environment. transfer can be passed as a list of objects that are to be transferred rather than cloned.

fun postMessage(message: Any?, options: StructuredSerializeOptions = definedExternally)
Link copied to clipboard
fun terminate()

Aborts worker's associated global environment.