Class EsThread<ApiType>

EsThreads

Some worker errors (unhandled rejection, uncaught exceptions, posting of incorrect results/errors) are dispatched by threads. You can use thread.addEventListener("error", ...) to recive those, but they're not particularily useful, aside from maybe debugging and testing.

Also, for SharedWorker threads: unhandled rejection and uncaught exceptions will not be delivered until a client connects. They are delivered only to the last connected client.

Example

const thread = await EsThread.Spawn<HelloWorldApiType>(
new Worker(new URL("threads/valid/hello-world.worker.ts", import.meta.url),
{type: "module"}));

Type Parameters

Hierarchy

  • EventTarget
    • EsThread

Implements

  • Terminable

Constructors

Properties

interface: MessagePort | Worker
methods: ProxyModule<ApiType> = ...

Access the thread API.

options: Readonly<EsThreadOptions>
tasks: Map<string, EsTaskPromise<any>> = ...
threadUID: string = ...

The threads UID.

worker: AbstractWorker

Accessors

Methods

  • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

    The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

    When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

    When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

    When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

    If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

    The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

    When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

    When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

    When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

    If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

    The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Type Parameters

    • Args extends any[]

    • ReturnType

    Parameters

    • method: string

    Returns ProxyFunction<Args, ReturnType>

  • 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

  • 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

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    MDN Reference

    Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Returns a promise that resolves when all tasks are resolved and rejects when any task rejects.

    Returns Promise<void>

  • Returns a promise that resolves when all tasks are settled.

    Returns Promise<void>

  • Terminate this thread.

    Waits for all tasks to settle. If tasks resolving is required, call EsThread#resolved before calling EsThread#terminate.

    Parameters

    • Optional forceTerminateShared: boolean

      If you want to make sure SharedWorkers abort. Probably not a great idea, but one might want to do it.

    Returns Promise<void>

  • Parameters

    • rawArgs: any[]

    Returns {
        args: any[];
        transferables: Transferable[];
    }

    • args: any[]
    • transferables: Transferable[]

Generated using TypeDoc