Creates a new ThreadPool.
OptionalpoolSize: numberThe number of Web Workers to spawn. Defaults to navigator.hardwareConcurrency (or 4).
Terminates all workers and cleans up memory.
Executes a function on a background worker thread.
The function to execute. WARNING: This function is serialized to a string.
It cannot access variables, imports, or context outside its own scope.
Everything it needs must be passed in via the data parameter.
The input data passed to the function. Must be JSON serializable.
Optional array of Transferable objects to pass by reference (zero-copy).
A Promise resolving with the function's return value.
A generic Web Worker pool for offloading heavy CPU tasks. Uses Blob URLs to dynamically spawn workers without requiring external script files.
Example