Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractWorker Abstract

A base class for all worker implementations.

remarks

Derived classes should override the AbstractWorker.onStart(...) method in order to provide an implementation for the worker, and then apply the @worker(...) class decorator to the class so that the worker is started in its own dedicated worker thread based on the current runtime.

All methods and properties of AbstractWorker will throw an error if a derived class has not been decorated with the @worker(...) class decorator.

Hierarchy

  • AbstractWorker

Implements

Index

Constructors

Properties

onMessage: TypedEvent<WorkerMessage<unknown>>

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().

  • Gets the current worker state.

    Returns WorkerStateFlags

    A WorkerStateFlags value that describes the current state of the worker.

Methods

  • onStart(): void | Promise<void>
  • The method that provides the worker implementation when the worker is started.

    remarks

    This method must be overriden by types that derive from AbstractWorker in order to provide their specific worker implementation.

    virtual

    Returns void | 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