Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WorkerLoader

Set of Worker loading and initialization helpers:

Hierarchy

  • WorkerLoader

Index

Properties

Static dependencyUrlMapping

dependencyUrlMapping: {}

Type declaration

  • [name: string]: string

Static directlyFallbackToBlobBasedLoading

directlyFallbackToBlobBasedLoading: boolean = false

Static sourceLoaderCache

sourceLoaderCache: Map<string, Promise<string>> = new Map<string, Promise<string>>()

Methods

Static fetchScriptSourceToBlobUrl

  • fetchScriptSourceToBlobUrl(scriptUrl: string): Promise<string>
  • 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

Static startWorker

  • startWorker(scriptUrl: string, timeout?: number): Promise<Worker>

Static startWorkerBlob

  • startWorkerBlob(scriptUrl: string, timeout: number): Promise<Worker>
  • 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>

Static startWorkerImmediately

  • startWorkerImmediately(scriptUrl: string, timeout: number): Promise<Worker>

Static waitWorkerInitialized

  • waitWorkerInitialized(worker: Worker, timeout: number): 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