Members
services :object.<(Worker|object)>
- See:
-
- {setService}
Map of channel name to worker or local service provider. If the entry is a Worker, the service is provided by an object on that worker. Otherwise, the service is provided locally and methods on the service will be called directly.
Type:
- object.<(Worker|object)>
workerClass :function
The constructor we will use to recognize workers.
Type:
- function
workers :Array
List of workers attached to this dispatcher.
Type:
- Array
Methods
(protected) _getServiceProvider(service) → {Object}
Fetch the service provider object for a particular service name.
Parameters:
Name | Type | Description |
---|---|---|
service |
string | the name of the service to look up |
Returns:
- the means to contact the service, if found
- Type
- Object
(protected) _onDispatchMessage(worker, message) → {Promise|undefined}
Handle a call message sent to the dispatch service itself
Parameters:
Name | Type | Description |
---|---|---|
worker |
Worker | the worker which sent the message. |
message |
DispatchCallMessage | the message to be handled. |
Returns:
- a promise for the results of this operation, if appropriate
- Type
- Promise | undefined
addWorker(worker)
Add a worker to the message dispatch system. The worker must implement a compatible message dispatch framework. The dispatcher will immediately attempt to "handshake" with the worker.
Parameters:
Name | Type | Description |
---|---|---|
worker |
Worker | the worker to add into the dispatch system. |
callSync(service, method, …argsopt) → {*}
Synchronously call a particular method on a particular service provided locally. Calling this function on a remote service will fail.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
service |
string | the name of the service. |
|
method |
string | the name of the method. |
|
args |
* |
<optional> <repeatable> |
the arguments to be copied to the method, if any. |
Returns:
- the return value of the service method.
- Type
- *
setService(service, provider) → {Promise}
Set a local object as the global provider of the specified service. WARNING: Any method on the provider can be called from any worker within the dispatch system.
Parameters:
Name | Type | Description |
---|---|---|
service |
string | a globally unique string identifying this service. Examples: 'vm', 'gui', 'extension9'. |
provider |
object | a local object which provides this service. |
Returns:
- a promise which will resolve once the service is registered.
- Type
- Promise
setServiceSync(service, provider)
Synchronously set a local object as the global provider of the specified service. WARNING: Any method on the provider can be called from any worker within the dispatch system.
Parameters:
Name | Type | Description |
---|---|---|
service |
string | a globally unique string identifying this service. Examples: 'vm', 'gui', 'extension9'. |
provider |
object | a local object which provides this service. |