https://github.com/pdmlab/net-retry-connect
Attempt to connect to net Sockets using retry patterns
https://github.com/pdmlab/net-retry-connect
Last synced: 11 months ago
JSON representation
Attempt to connect to net Sockets using retry patterns
- Host: GitHub
- URL: https://github.com/pdmlab/net-retry-connect
- Owner: PDMLab
- License: bsd-3-clause
- Created: 2016-02-24T20:42:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-29T07:04:25.000Z (almost 10 years ago)
- Last Synced: 2025-02-05T19:03:50.823Z (11 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# net-retry-connect
Attempt to connect to net Sockets using retry patterns.
```net-retry-connect``` is based on the Node.js ```net``` module as well as the [retry](https://www.npmjs.com/package/retry) module.
## Installation
```npm install net-retry-connect --save```
## API
### retryConnect.to(options, callback)
```options``` provides this options:
* ```port```: the TCP port
* ```host```: optional, defaults to ```'localhost'```
* ```retryOptions```, optional, see retry options for [retry.operation](https://github.com/tim-kos/node-retry#retryoperationoptions)
```callback``` returns a client object if connection has been successful. Otherwise it returns the error.
```js
var retryConnect = require('net-retry-connect');
retryConnect.to({port: 3000, host: 'localhost'}, function (error, client) {
// use the client
});
```
#### Usage of retryOptions
```js
var retryConnect = require('net-retry-connect');
// retry for 2 seconds only
var retryOptions = {
retries: 2,
factor: 1
};
retryConnect.to({port: 3000, host: 'localhost', retryOptions: retryOptions }, function (error, client) {
// use the client
});
```
## Running the tests:
```
npm install
npm test
```