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

interface Worker {
    onerror: null | ((this, ev) => any);
    onmessage: null | ((this, ev) => any);
    onmessageerror: null | ((this, ev) => any);
    addEventListener<K>(type, listener, options?): void;
    addEventListener(type, listener, options?): void;
    dispatchEvent(event): boolean;
    postMessage(message, transfer): void;
    postMessage(message, options?): void;
    removeEventListener<K>(type, listener, options?): void;
    removeEventListener(type, listener, options?): void;
    terminate(): void;
}

Hierarchy (view full)

Properties

onerror: null | ((this, ev) => any)

Type declaration

onmessage: null | ((this, ev) => any)

Type declaration

    • (this, ev): any
    • Parameters

      • this: Worker
      • ev: MessageEvent<any>

      Returns any

onmessageerror: null | ((this, ev) => any)

Type declaration

    • (this, ev): any
    • Parameters

      • this: Worker
      • ev: MessageEvent<any>

      Returns any

Methods

  • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • 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.

    MDN Reference

    Parameters

    Returns void

  • Parameters

    Returns void

  • Aborts worker's associated global environment.

    MDN Reference

    Returns void

Generated using TypeDoc