Class Worker

Hierarchy

  • Worker

Constructors

Properties

Methods

Constructors

  • Constructor to create a new thread (worker) with an API close to the WebWorkers. module_filename is a string specifying the module filename which is executed in the newly created thread. As for dynamically imported module, it is relative to the current script or module path. Threads normally don’t share any data and communicate between each other with messages. Nested workers are not supported. An example is available in tests/test_worker.js.

    Parameters

    • module_filename: string

    Returns Worker

Properties

onmessage: ((msg: any) => void)

Type declaration

    • (msg: any): void
    • Getter and setter. Set a function which is called each time a message is received. The function is called with a single argument. It is an object with a data property containing the received message. The thread is not terminated if there is at least one non null onmessage handler.

      Parameters

      • msg: any

      Returns void

parent?: Worker

In the created worker, Worker.parent represents the parent worker and is used to send or receive messages.

Methods

  • Send a message to the corresponding worker. msg is cloned in the destination worker using an algorithm similar to the HTML structured clone algorithm. SharedArrayBuffer are shared between workers.

    Current limitations: Map and Set are not supported yet.

    Parameters

    • msg: any

    Returns void

Generated using TypeDoc