On this page

# NetworkRequest

NetworkRequest

This is the Network Request model. It handles the lifecycle of a request made for a network node and keeps track of the responses received. Based on the notifications intercepted from the node, it attempts to resolve or reject the promise returned upwards.

## Constructor

### new NetworkRequest(handler, onSuccess, onFail)

The NetworkRequest constructor.

Parameters:

Name | Type | Description
--- | --- | ---
`handler` | NetworkRequestsHandler |
`onSuccess` | function |
`onFail` | function |

Source
  - models/network.requests.handler.js, line 116

## Classes

NetworkRequest

## Members

### closed :boolean|null

Request status.

Type:

- boolean | null

Source
  - models/network.requests.handler.js, line 129

### id :string|null

Network request id.

Type:

- string | null

Source
  - models/network.requests.handler.js, line 122

### (private) nodeRequestsHandler :NetworkRequestsHandler

Reference to the network request handler that keeps track of all the open requests.

Type:

- NetworkRequestsHandler

Source
  - models/network.requests.handler.js, line 187

### onFail :function

Fail callback.

Type:

- function

Source
  - models/network.requests.handler.js, line 143

### onSuccess :function

Success callback.

Type:

- function

Source
  - models/network.requests.handler.js, line 136

### (private) strategy :function

The strategy to use when interpreting the stream of received notifications.

Type:

- function

Source
  - models/network.requests.handler.js, line 168

### (private) targets :Object

A dictionary of targets to track when processing responses. It allows for correctly interpreting the flow of notifications received from the nodes.

Type:

- Object

Source
  - models/network.requests.handler.js, line 152

### (private) timeoutIds :Object

Handlers for the timeouts.

Type:

- Object

Source
  - models/network.requests.handler.js, line 176

### (private) transactionNotifications :Array.<Object>

A temporary storage for all the incoming notifications. Will be bubbled upwards when resolving the promise.

Type:

- Array.<Object>

Source
  - models/network.requests.handler.js, line 160

## Methods

### canResolve() → {boolean}

Returns `true` if all the transaction targets were hit and the responses are all successful.

Source
  - models/network.requests.handler.js, line 289

Returns:

Type:
  boolean

### clearCompletionTimeout() → {NetworkRequest}

Clears the timeout for the resolving of the transaction.

Source
  - models/network.requests.handler.js, line 394

Returns:

Type:
  NetworkRequest

### clearFirstResponseTimeout() → {NetworkRequest}

Clears the timeout for the first network response.

Source
  - models/network.requests.handler.js, line 380

Returns:

Type:
  NetworkRequest

### close() → {NetworkRequest}

Closes the transaction and removes the completion timeout.

Source
  - models/network.requests.handler.js, line 227

Returns:

Type:
  NetworkRequest

### getId() → {string|null}

Returns the transaction id.

Source
  - models/network.requests.handler.js, line 209

Returns:

Type:
  string | null

### isClosed() → {boolean}

Returns the status of the transaction.

Source
  - models/network.requests.handler.js, line 218

Returns:

Type:
  boolean

### isComplete() → {boolean}

Returns `true` if all the transaction targets were hit. The completion status concerns only if all the expected notifications were received, it doesn't offer information about the success of the request.

Source
  - models/network.requests.handler.js, line 278

Returns:

Type:
  boolean

### listWatches() → {Array.<Array.<(string|null)>>}

Returns all the notification `path`s watched by the current transaction.

Source
  - models/network.requests.handler.js, line 266

Returns:

Type:
  Array.<Array.<(string|null)>>

### process(message)

Main processing function. All notifications should be routed through this method. When first notification is received, the timeout for the first response is cleared.

Parameters:

Name | Type | Description
--- | --- | ---
`message` | Object |

Source
  - models/network.requests.handler.js, line 332

### reject()

Attempt to reject the transaction.

Source
  - models/network.requests.handler.js, line 416

### resolve()

Attempt to resolve the transaction.

Source
  - models/network.requests.handler.js, line 406

### setProcessingStrategy(strategy) → {NetworkRequest}

Loads a solving strategy for the current transaction.

Parameters:

Name | Type | Description
--- | --- | ---
`strategy` | function |

Source
  - models/network.requests.handler.js, line 320

Returns:

Type:
  NetworkRequest

### setTimeoutIds(firstResponseTimeoutId, completionTimeoutId) → {NetworkRequest}

Sets the timeout ids for the two timeout callbacks.

- firstResponseTimeoutId is the callback id for the timer waiting for the first network response
- completionTimeoutId is the callback id for the timer keeping track of the successful completion of the whole transaction.

Parameters:

Name | Type | Description
--- | --- | ---
`firstResponseTimeoutId` | number |
`completionTimeoutId` | number |

Source
  - models/network.requests.handler.js, line 358

Returns:

Type:
  NetworkRequest

### timeout()

Trigger the timeout on the transaction.

Source
  - models/network.requests.handler.js, line 368

### updateTarget(notification) → {NetworkRequest}

Pushes a notification onto the list of notifications linked to a specific target `path`.

Parameters:

Name | Type | Description
--- | --- | ---
`notification` | Object |

Source
  - models/network.requests.handler.js, line 301

Returns:

Type:
  NetworkRequest

### watch(path) → {NetworkRequest}

Registers a notification path to track when resolving the transaction.

Parameters:

Name | Type | Description
--- | --- | ---
`path` | Array.<string> |

Source
  - models/network.requests.handler.js, line 240

Returns:

Type:
  NetworkRequest

### watches(path) → {boolean}

Returns `true` if the current transaction is keeping track of a specific notification `path`.

Parameters:

Name | Type | Description
--- | --- | ---
`path` | Array.<string> |

Source
  - models/network.requests.handler.js, line 257

Returns:

Type:
  boolean

Type anything to view search result