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)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open external fun dispatchEvent(event: Event): Boolean
Link copied to clipboard
external fun postMessage(message: 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.

external fun postMessage(message: JsAny?, options: StructuredSerializeOptions = definedExternally)
external fun postMessage(message: String, transfer: ReadonlyArray<Transferable>)
external fun postMessage(message: String, options: StructuredSerializeOptions = definedExternally)
Link copied to clipboard
external 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
external fun <T : Event> when(type: EventType<T>, options: ObservableEventListenerOptions?): Observable<T>