Worker

open class Worker(scriptURL: TrustedScriptURL, options: WorkerOptions = definedExternally) : EventTarget, AbstractWorker, MessageEventTarget(source)

The Worker interface of the Web Workers API represents a background task that can be created via script, which can send messages back to its creator.

MDN Reference

Constructors

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

Functions

Link copied to clipboard
open fun dispatchEvent(event: Event): Boolean
Link copied to clipboard
fun postMessage(message: ERROR CLASS: Symbol not found for JsAny??, transfer: ReadonlyArray<Transferable>)

The postMessage() method of the Worker interface sends a message to the worker. The first parameter is the data to send to the worker. The data may be any JavaScript object that can be handled by the structured clone algorithm.

fun postMessage(message: ERROR CLASS: Symbol not found for JsAny??, options: StructuredSerializeOptions = definedExternally)
fun postMessage(message: String, transfer: ReadonlyArray<Transferable>)
fun postMessage(message: String, options: StructuredSerializeOptions = definedExternally)
Link copied to clipboard
fun terminate()

The terminate() method of the Worker interface immediately terminates the Worker. This does not offer the worker an opportunity to finish its operations; it is stopped at once.

Link copied to clipboard