WorkerImplementation<T> Type
Given an interface T that defines the operations provided by a worker, produce an interface to which the implementation of those operations must conform. The return type of each function is enhanced to permit supplying a list of values to be transferred from the worker to the main thread. Multi-argument functions are converted to functions accepting a single tuple of arguments.
- Every return type
R
is converted toWorkerReturnType<R>
. zeroArgFunc(): R
becomeszeroArgFunc(): R | { result: R; transfer: Transferable[]; }
.oneArgFunc(arg: U): R
becomesoneArgFunc(arg: U): R | { result: R; transfer: Transferable[]; }
.multiArgFunc(arg1: U, arg2: V): R
becomesmultiArgFunc([U, V]): R | { result: R; transfer: Transferable[]; }
.
@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: 14 November, 2024
Found something wrong, missing, or unclear on this page?Raise an issue in our repo.