Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Mar 9, 2014
1 parent 5be7b90 commit 3139c27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -22,6 +22,28 @@ connection.when('available', function (err, db) {
});
```

## Heartbeat

Heartbeat is useful, when you want check connection from time to time. For example, if you working with mongodb and cache connection to db - what happens when server, which connection binded to goes to heaven? Connection is lost and programmer should recreate it.

__Note:__ for now there is no way to stop heartbeats.

```js
var connectOnce = require('connect-once');

var connection = new connectOnce({
heartbeat: function (db, beat) {
db.stats(function (err) {
if (!err) { beat(); }
});
}
}, MongoClient.connect, 'mongodb://localhost/test');

connection.when('available', function (err, db) {
// Do stuff
});
```

## API

Read the [documentation of Connection class](http://floatdrop.github.io/connect-once/Connection.html).
Expand Down
7 changes: 5 additions & 2 deletions index.js
@@ -1,7 +1,5 @@
'use strict';

var async = require('async');

/**
* Creates event emitter, which will pass connection to listeners,
* when connect function callback will be called.
Expand Down Expand Up @@ -89,6 +87,11 @@ Connection.prototype.retry = function retry() {
}.bind(this), this.options.reconnectWait);
};

/**
* This method starts checking connection with heartbeat function.
*
* @method
*/
Connection.prototype.checkPulse = function checkPulse(args) {
var timer = setTimeout(function () {
this.retry(new Error('Connection is dead'));
Expand Down
5 changes: 1 addition & 4 deletions package.json
Expand Up @@ -27,8 +27,5 @@
"bugs": {
"url": "https://github.com/floatdrop/connect-once/issues"
},
"homepage": "https://github.com/floatdrop/connect-once",
"dependencies": {
"async": "~0.2.10"
}
"homepage": "https://github.com/floatdrop/connect-once"
}

0 comments on commit 3139c27

Please sign in to comment.