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
|
||||||||||||||||||||||||||||||
connect |
function | Function to be called with following arguments to get connection | |||||||||||||||||||||||||||||||
arguments |
Object |
<optional> <repeatable> |
Arguments for connect function |
Methods
-
checkPulse()
-
This method starts checking connection with heartbeat function.
-
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.
-
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`.
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.
-
reconnect
-
Emitted on each reconnection try. Contains error, that happened on connection try