Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WorkerSelf

Wrapper for the WorkerGlobalScope in the browser/deno and MessagePort in NodeJS.

This class is not meant to be used directly, instead, the WorkerSelf module exports a single instance of this class.

Hierarchy

  • WorkerSelf

Index

Accessors

ready

  • get ready(): Promise<void>
  • Returns a promise that, when resolved, indicates when the WorkerSelfWrapper is ready to be used.

    Returns Promise<void>

self

  • get self(): WorkerGlobalScope | MessagePort

Methods

addEventListener

  • addEventListener(event: string, listener: (...args: any[]) => void): void
  • Minimum viable API to provide the browser's addEventListener API for all platforms.

    Parameters

    • event: string

      The event to subscribe to.

    • listener: (...args: any[]) => void

      Event handler function

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

Private initialize

  • initialize(): Promise<void>
  • Initializes the underlying messaging system for the platform.

    Returns Promise<void>

off

  • off(event: string, listener: (...args: any[]) => void): void
  • Minimum viable API to provide node's off API for all platforms.

    Parameters

    • event: string

      The event to unsubscribe from

    • listener: (...args: any[]) => void

      Event handler function that was registered using either on or addEventListener

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

on

  • on(event: string, listener: (...args: any[]) => void): void
  • Minimum viable API to provide node's on API for all platforms.

    Parameters

    • event: string

      The event to subscribe to.

    • listener: (...args: any[]) => void

      Event handler function

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

postMessage

  • postMessage(message: any, transferList?: ArrayBuffer[]): void
  • Posts a message to the code owner of this worker thread, this is meant to be homogeneous across platforms.

    Parameters

    • message: any

      The message to send to the worker, can be anything that is supported by the structured clone algorithm

    • Optional transferList: ArrayBuffer[]

      Objects to transfer to the worker, limited to ArrayBuffer objects as a minimum viable API on all platforms.

    Returns void

removeEventListener

  • removeEventListener(event: string, listener: (...args: any[]) => void): void
  • Minimum viable API to provide the browser's removeEventListener API for all platforms.

    Parameters

    • event: string

      The event to unsubscribe from

    • listener: (...args: any[]) => void

      Event handler function that was registered using either on or addEventListener

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

Generated using TypeDoc