Skip to main content
Branch: Release Candidate

Worker

Deprecated

Index

Constructors

constructor

  • new Worker(filePath: string): Worker
  • Creates a new worker.

    Remarks

    This will throw an error if the resource has reached its maximum amount of workers. See maxWorkers.

Properties

publicreadonlyfilePath

filePath: string

The file path that was used to create this worker.

publicreadonlyisPaused

isPaused: boolean

Whether the worker is currently paused. See pause and resume.

publicreadonlyvalid

valid: boolean

Whether this worker is still valid. See destroy.

publicstaticreadonlymaxWorkers

maxWorkers: number

Maximum available workers per resource.

Methods

publicdestroy

  • destroy(): void
  • Destroys the worker and stops it.

    Remarks

    This permanently sets valid to false.

publicemit

  • emit(eventName: string, ...args: any[]): void
  • Emits the specified event to the worker.

    Remarks

    This can be called before the worker is started.

publicoff

  • off(eventName: string, listener: (...args: any[]) => void): void
  • Unsubscribes from Worker event handler with specified listener.

    Remarks

    Listener should be of the same reference as when event was subscribed.

publicon

  • on(eventName: string, callback: (...args: any[]) => void): void
  • Listens to an event emitted by the worker.

    Remarks

    The event handlers should be registered before starting the worker.

publiconce

  • once(eventName: string, callback: (...args: any[]) => void): void
  • Listens to an event emitted by the worker once.

    Remarks

    See on.

publicpause

  • pause(): void
  • Pauses execution of the worker.

    Remarks

    This completely stops the JavaScript event loop of the worker but events can still be received (and will be handled once the worker is resumed).

publicresume

  • resume(): void
  • Resumes execution of the worker.

    Remarks

    See pause.

publicstart

  • start(): void
  • Starts the worker script.

publicstaticaddSharedArrayBuffer

  • addSharedArrayBuffer(buffer: SharedArrayBuffer): number
  • Adds a shared array buffer to the workers array buffer pool.

    Remarks

    Make sure to remove the array buffer once you are done with it by calling removeSharedArrayBuffer, otherwise you are creating a memory leak.

publicstaticremoveSharedArrayBuffer

  • removeSharedArrayBuffer(id: number): void
  • Removes the shared array buffer from the workers array buffer pool.