Class: Connection

Connection

new Connection(options, connect, arguments)

Creates event emitter, which will pass connection to listeners, when connect function callback will be called.
Parameters:
Name Type Argument Description
options Object <optional>
Options for establishing connection
Properties
Name Type Argument Default Description
retries Number <optional>
5 Number of retries before emitting error
reconnectWait Number <optional>
1000 Milliseconds between reconnect trys.
heartbeat function <optional>
Function, that will check connection from time to time.
heartbeatTimeout Number <optional>
800 Milliseconds before heartbeat function counts as failed.
heartbeatInterval Number <optional>
1000 Milliseconds between heartbeats calls.
connect function Function to be called with following arguments to get connection
arguments Object <optional>
<repeatable>
Arguments for connect function
Source:

Methods

checkPulse()

This method starts checking connection with heartbeat function.
Source:

retry()

Callback, that will be passed to connect function. When connection is available it will store results of connect function and emit `available` event with them. If error returned from connect function it will retry to connect accordingly to options and emit `available` with error as first argument on retries == 0.
Source:

when()

This is wrapper around `once` method. If event is equal `available` - then it will check saved results from callback, and they absent attach `callback` with `once` method on event `available`.
Source:

Events

available

Emitted once, when connection is available. For retrieving saved results use `when` method. Contains all arguments that was called by connect function callback.
Source:

reconnect

Emitted on each reconnection try. Contains error, that happened on connection try
Source: