Class WorkerLoader

Set of Worker loading and initialization helpers:

Hierarchy

  • WorkerLoader

Constructors

Properties

dependencyUrlMapping: {
    [name: string]: string;
} = {}

Type declaration

  • [name: string]: string
directlyFallbackToBlobBasedLoading: boolean = false
sourceLoaderCache: Map<string, Promise<string>> = ...

Methods

  • Fetch script source as Blob url.

    Reuses results, if there are many simultaneous requests.

    Parameters

    • scriptUrl: string

      web worker script URL

    Returns Promise<string>

    promise that resolves to url of a Blob with script source code

  • Start worker "via blob" by first loading worker script code with [[fetch]], creating Blob and attempting to start worker from blob url. Waits (using [[waitWorkerInitialized]]) for successful worker start.

    Parameters

    • scriptUrl: string

      web worker script URL

    • timeout: number

    Returns Promise<Worker>

  • Start worker, loading it immediately from scriptUrl. Waits (using [[waitWorkerInitialized]]) for successful worker start.

    Parameters

    • scriptUrl: string

      web worker script URL

    • timeout: number

    Returns Promise<Worker>

  • Waits for successful Web Worker start.

    Expects that worker script sends initial message.

    If first event is message then assumes that worker has been loaded sussesfully and promise resolves to worker object passed as argument.

    If first event is 'error', then it is assumed that worker failed to load and promise is rejected.

    (NOTE: The initial 'message' - if received - is immediately replayed using worker's dispatchEvent, so application code can also consume it as confirmation of successful worker initialization.

    We must resolve/reject promise at some time, so it is expected that any sane application will be able to load worker code in some amount of time.

    Parameters

    • worker: Worker

      [[Worker]] instance to be checked

    • timeout: number

      timeout in milliseconds, in which worker should set initial message

    Returns Promise<Worker>

    Promise that resolves to worker on success

Generated using TypeDoc