Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WorkerInterface

Interface meant to be used within a Worker to handle messages through the use of objects that comply with the rules set by TaskExecutor. Messages are ony handled if at least one TaskExecutor has been added.

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

Hierarchy

  • WorkerInterface

Index

Properties

Private executorList

executorList: TaskExecutor[] = []

List of objects to be used as TaskExecutors

Methods

addTaskExecutor

Private handleMessage

  • handleMessage(e: MessageEvent): Promise<void>
  • Handles messages from the worker's owner, once a message is received, it looks for a task and a matching TaskExecutor for it. If an executor for a task is found and the task succeeds, the result of the task is sent back as a message to the worker's owner, an error message with an explanation is sent otherwise.

    Parameters

    • e: MessageEvent

      Event from the worker's owner.

    Returns Promise<void>

Private installEventHandlers

  • installEventHandlers(): Promise<void>
  • Registers this instance to listen for message events from the worker's owner.

    Returns Promise<void>

removeTaskExecutor

  • Removes a [TaskExecutor]] from this WorkerInterface. If, after removing the specified object, there are no more executors left, the interface will stop handling messages from the worker's owner.

    Parameters

    Returns void

Private sendError

  • sendError(reason: string): void
  • Utility function to send an error message back to the worker's owner.

    Parameters

    • reason: string

      The reason for the error.

    Returns void

Private sendSuccess

  • sendSuccess(data?: any | null, transferable?: ArrayBuffer[]): void
  • Utility function to send a success message back to the worker's owner.

    Parameters

    • Default value data: any | null = null

      An object that will be sent with the message.

    • Optional transferable: ArrayBuffer[]

      Transferable objects, if any.

    Returns void

Private uninstallEventHandlers

  • uninstallEventHandlers(): void
  • Unregisters this instance from listening for message events from the worker's owner.

    Returns void

Generated using TypeDoc