Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WorkerWrapper

Wraps a worker instance on supported platforms and exposes a shared minimum viable API, while providing access to the original instance for advanced, platform specific functionality.

Hierarchy

  • WorkerWrapper

Index

Constructors

constructor

Accessors

worker

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

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, transferable?: ArrayBuffer[]): void
  • Posts a message to the worker code, 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 transferable: 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

terminate

  • terminate(): void
  • Terminates the underlying worker instance and invalidates the handle to it. This WorkerWrapper instance will become unusable after calling this method.

    Returns void

Static createWorker

  • createWorker(src: string, options: WorkerOptions): Promise<WorkerWrapper>
  • Utility function to create a Worker instance and wrap it. Supports browsers, NodeJS and deno.

    Parameters

    • src: string

      A string containing the path to the worker source. Can be an absolute or relative path.

    • options: WorkerOptions

      Options to use when creating the worker.

    Returns Promise<WorkerWrapper>

Generated using TypeDoc