new Agent()
Agent class constructor.
Do not instantiate directly from application.
Agent instances are created by Broker.
You may define a customized Agent by subclassing. When
worker class is registered, set Worker#agent property to the custom agent
so that broker will use the custom Agent class when returning an instance
of the Agent as a result of Broker#createWorker() or Broker#findWorker().
Properties:
| Name | Type | Description |
|---|---|---|
id |
string | Corresponding worker ID (read-only) |
Methods
ask(method, data, cbopt) → {Promise}
Ask operation for corresponding Worker.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
method |
string | Method name. |
|
data |
object | Data to send to the remote worker. |
|
cb |
Agent~askCallback |
<optional> |
Callback from this method. |
Returns:
Returns a Promise if cb is not supplied.
See Agent~askCallback
- Type
- Promise
tell(method, data, cbopt) → {Promise}
Tell operation for corresponding Worker.
Unlike #ask, this operation does not guarantee that the data is received
by the remote worker. This operation only guarantees that the data was
written into the destination is message queue.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
method |
string | Method name. |
|
data |
object | Data to send to the remote worker. |
|
cb |
Agent~tellCallback |
<optional> |
Callback from this method. |
Returns:
Returns a Promise if cb is not supplied.
See Agent~tellCallback
- Type
- Promise
Type Definitions
askCallback(err, data)
Callback function for Agent#ask.
Unlike #tell, this operation makes sures that the data is received
by the remote worker. The transaction remains until the remote worker
responds with a data, much like HTTP transaction.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |
data |
object | Response data. |
tellCallback(err)
Callback function for Agent#tell.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |