new PeerAction(peerIdentifier, connectionType, actionType)
An action that has been given to the pool to manage.
When an action is created its state MUST be CREATED.
Parameters:
| Name | Type | Description |
|---|---|---|
peerIdentifier |
string | |
connectionType |
module:thaliMobile.connectionTypes | |
actionType |
string |
- Source:
Members
(private) actionState :module:thaliPeerAction.actionState
The current state of the action
Type:
- Source:
(private) actionType :string
The type of action that will be taken
Type:
- string
- Source:
(private) connectionType :module:thaliMobile.connectionTypes
The type of connection the requests will be sent over
Type:
- Source:
(private) peerIdentifier :string
The remote peer this action targets
Type:
- string
- Source:
Methods
getActionState() → {*}
Returns:
- Type
- *
kill() → (nullable) {Error}
Tells an action to stop executing immediately and synchronously.
If the action is already dead then there is no error. If the action isn't dead then once it is killed off it MUST return null to its promise as defined above.
This method is idempotent so multiple calls MUST NOT directly cause a state change.
When kill returns the action's state MUST be set to KILLED.
Returns:
- Type
- Error
start(httpAgentPool) → {Promise.<?Error>}
Tells the action to begin processing. When the action has completed it will resolve the returned promise successfully with a null value. Once the returned promise resolves then the pool MUST stop tracking this action. Errors from the promise results SHOULD be logged.
Start is idempotent so multiple calls MUST NOT directly cause a state change. That is, if the action hasn't started then the first call to start will start it and further calls will accomplish nothing.
If start is called on an action that has completed, successfully or not, then an error object MUST be returned with the value "action has completed."
If the action fails due to a network issue it is important that this be reported to the pool because it can use this information to decide how to schedule things. The pool is expected to have subscribed for events like module:thaliMobile.event:networkChanged and module:thaliMobile.event:discoveryAdvertisingStateUpdate and so understand when there are general connections failures. The action MUST use the following error messages if the related errors occur.
"Could not establish TCP connection" - This error indicates that the action gave up because it got too many errors trying to connect over TCP to its target peer.
"Could establish TCP connection but couldn't keep it running" - In a HTTP context this primarily to cases where a connection appears to exist but all HTTP requests never seem to be able to successfully complete.
When start returns the action's state MUST be STARTED.
Parameters:
| Name | Type | Description |
|---|---|---|
httpAgentPool |
http.Agent | The HTTP client connection pool to use when making requests to the requested peer. |
Returns:
returns a promise that will resolve when the action is done. Note that if kill is called on an action then it MUST still return success with null. After all, kill doesn't reflect a failure of the action but a change in outside circumstances.
- Type
- Promise.<?Error>