Type alias WorkerInitFunction<T>

WorkerInitFunction<T>: ((message?: T) => Promise<void> | void)

Type Parameters

  • T = unknown

    Anything passed as initArgs in configureAndStart, with Transferable objects inlined.

Type declaration

    • (message?: T): Promise<void> | void
    • A function for setting up a Web Worker environment before it starts processing jobs. May be sync or async. Worker functions cannot use variables defined outside of their block, because the function code itself is inlined and written to the Web Worker source code.

      You should pass any dynamic data that won't change between jobs using initArgs in configureAndStart, and parse/use them in the init function.

      If you need to store some global state to be used later when processing jobs, you can write a property to self, which will be a DedicatedWorkerGlobalScope. But be careful not to overwrite any browser-initialized properties in there!

      Parameters

      • Optional message: T

      Returns Promise<void> | void

Generated using TypeDoc