WorkerInterface<T> Type

Given an interface T that defines the operations provided by a worker, produce an interface that can be used to asynchronously invoke those operations from the main thread, optionally passing an array of values to be transferred from the main thread to the worker.

  • Every return type is converted to a Promise (i.e., every function becomes async)>.
  • zeroArgFunc(): R becomes async zeroArgFunc(): Promise<R>.
  • oneArgFunc(arg: U): R becomes async oneArgFunc(arg: U, transfer?: Transferable[]): Promise<R>.
  • multiArgFunc(arg1: U, arg2: V): R becomes async multiArgFunc(args: [U, V], transfer?: Transferable[]): Promise<R>.

@note All parameters of all methods of T must support structured cloning - attempts to pass functions, instances of classes, DOM nodes, WebGL resources, and other non-cloneable types will compile but fail at run-time.

Defined in

Last Updated: 28 October, 2024