Creates a new ConcurrentWorkerSet
.
Creates as many Web Workers as specified in options.workerCount
, from the script provided
in options.scriptUrl
. If options.workerCount
is not specified, the value specified in
navigator.hardwareConcurrency
is used instead.
The worker set is implicitly started when constructed.
The number of workers for debugging and profiling.
The number of workers for debugging and profiling.
The size of the request queue for debugging and profiling.
Is true
if the workers have been terminated.
The number of workers started for this worker set. The value is undefined
until the workers
have been created.
Registers an event listener for events that originated in a web worker, for a given
serviceId
. You can only set one event listener per serviceId
.
The service to listen to.
The callback to invoke for matching events.
Adds an external reference and increments the internal reference counter by one.
To implement a reference-count based automatic resource cleanup, use this function with removeReference.
Posts a message to all workers.
The message to send.
Optional buffers to transfer to the workers.
Invokes a request that expects responses from all workers.
Send RequestMessage to all workers and resolves when all workers have sent a matching ResponseMessage. Use this function to wait on request that need to happen on all workers before proceeding (like synchronous worker service creation).
The name of service, as registered with the [[WorkerClient]] instance.
The request to process.
An optional array of ArrayBuffer
s to transfer to the worker context.
Array of Promise
s that resolves with a response from each worker (unspecified
order).
Waits for service
to be initialized in all workers.
Each service that starts in a worker sends an isInitializedMessage to confirm that
it has started successfully. This method resolves when all workers in a set have
service
initialized.
Promise is rejected if any of worker fails to start.
The service identifier.
Destroys all workers immediately.
Resolves all pending request promises with a worker destroyed
error.
Use start to start this worker again.
Subclasses must call this function when a worker emits an event.
The event to dispatch.
Invokes a request that expects a response from a random worker.
Sends RequestMessage and resolves when a matching ResponseMessage is received from workers. Use this function when interfacing with "RPC-like" calls to services.
The name of service, as registered with the [[WorkerClient]] instance.
The request to process.
An optional array of ArrayBuffer
s to transfer to the worker context.
An optional RequestController to store state of cancelling.
A Promise
that resolves with a response from the service.
Removes a previously set event listener for the given serviceId
.
The service from which to remove the event listeners.
Decrements the internal reference counter by 1.
When the internal reference counter reaches 0, this function calls dispose to clear the resources.
Use with addReference to implement reference-count based automatic resource cleanup.
Starts workers.
Use to start workers already stopped by stop or destroy calls.
Note: The worker set is implicitly started on construction - no need to call start on fresh instance.
optional, new worker set options
Stops workers.
Waits for all pending requests to be finished and stops all workers.
Use start to start this worker again.
Promise
that resolves when all workers are destroyed.
Generated using TypeDoc
A set of concurrent Web Workers. Acts as a Communication Peer for WorkerService instances running in Web Workers.
Starts and manages a certain number of web workers and provides a means to communicate with them using various communication schemes, such as:
The request queue holds all requests before they are stuffed into the event queue, allows for easy (and early) cancelling of requests. The workers now only get a single new RequestMessage when they return their previous result, or if they are idle. When they are idle, they are stored in m_availableWorkers.