An asynchronous web Worker which can load user-defined functions and await execution using Promises.

The worker name to be initialized

Worker initialization options

Should the worker run in debug mode?

Should the worker automatically load the primitives library?

Should the worker operates in script modes? Optional scripts.

Hierarchy (View Summary)

Properties

name: string

The name of this worker.

WORKER_HARNESS_JS: string = "scripts/worker.js"

A path reference to the JavaScript file which provides companion worker-side functionality.

Accessors

  • get ready(): Promise<any>

    A Promise which resolves once the Worker is ready to accept tasks

    Returns Promise<any>

Methods

  • Execute a task on a specific Worker.

    Parameters

    • functionName: string

      The named function to execute on the worker. This function must first have been loaded.

    • Optionalargs: any[] = []

      An array of parameters with which to call the requested function

    • Optionaltransfer: any[] = []

      An array of transferable objects which are transferred to the worker thread. See https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects

    Returns Promise<unknown>

    A Promise which resolves with the returned result of the function once complete.

  • Load a function onto a given Worker. The function must be a pure function with no external dependencies or requirements on global scope.

    Parameters

    • functionName: string

      The name of the function to load

    • functionRef: Function

      A reference to the function that should be loaded

    Returns Promise<unknown>

    A Promise which resolves once the Worker has loaded the function.

  • Returns void