Private
#tasksA queue of active tasks that this Worker is executing.
Private
#taskAn auto-incrementing task index.
Static
WORKER_A path reference to the JavaScript file which provides companion worker-side functionality.
A Promise which resolves once the Worker is ready to accept tasks
Load a function onto a given Worker. The function must be a pure function with no external dependencies or requirements on global scope.
The name of the function to load
A reference to the function that should be loaded
A Promise which resolves once the Worker has loaded the function.
Execute a task on a specific Worker.
The named function to execute on the worker. This function must first have been loaded.
Optional
args: any[] = []An array of parameters with which to call the requested function
Optional
transfer: any[] = []An array of transferable objects which are transferred to the worker thread. See https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects
A Promise which resolves with the returned result of the function once complete.
Private
#dispatchDispatch a task to a named Worker, awaiting confirmation of the result.
Data to dispatch to the Worker as part of the task.
An array of transferable objects which are transferred to the worker thread.
A Promise which wraps the task transaction.
Private
#onPrivate
#on
An asynchronous web Worker which can load user-defined functions and await execution using Promises.
Param: name
The worker name to be initialized
Param: options
Worker initialization options
Param: options.debug
Should the worker run in debug mode?
Param: options.loadPrimitives
Should the worker automatically load the primitives library?
Param: options.scripts
Should the worker operates in script modes? Optional scripts.