Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a worker that delegates internally to a worker thread that is created specifically for the current runtime.

Hierarchy

  • Worker

Implements

Index

Constructors

  • new Worker(filename: string | URL, args?: unknown[]): Worker
  • Initializes a new Worker.

    Parameters

    • filename: string | URL

      The string or URL describing the location of the worker script.

    • Optional args: unknown[]

      An optional array of arguments that will be sent to the worker when it is started.

    Returns Worker

Properties

args?: any
filename: any
onMessage: TypedEvent<WorkerMessage<unknown>>
platformWorker: any
promise: any
workerError: any
workerState: any

Accessors

  • get error(): string | Error
  • Gets the error state of the terminated worker.

    Returns string | Error

    A string or Error that describes the error state of the current worker; undefined if the current worker was forcibly terminated via WorkerLike.terminate().

Methods

  • onStart(): Promise<void>
  • Invoked when the current worker is started to create the internal worker thread based on the current runtime.

    virtual

    Returns Promise<void>

  • postMessage(data: Record<string, unknown>): Promise<void>
  • Sends a message to the worker.

    remarks

    Once the promise returned by this method resolves, it indicates that the message has been delivered to the worker and not that the worker has successfully processed the message.

    Parameters

    • data: Record<string, unknown>

      The data that should be posted to the current worker.

    Returns Promise<void>

    A Promise that resolves once data has been successfuly sent to the worker.

  • start(): Promise<void>
  • Starts the current worker.

    Returns Promise<void>

    A Promise that resolves when the current worker has completed executing.

  • terminate(): void
  • Signals the current worker to terminate immediately.

    Returns void

  • wait(): Promise<void>
  • Waits until the current worker has completed executing.

    Returns Promise<void>

    A Promise that resolves when the current worker has completed executing.

Generated using TypeDoc