Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Refactor setupTimer to retimer #318

Merged
merged 6 commits into from
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ OTHER DEALINGS IN THE SOFTWARE.
var async = require("async"),
uuid = require("uuid");

var retimer = require('retimer');

function nop() {}

/**
Expand Down Expand Up @@ -151,10 +153,6 @@ Client.prototype._setup = function() {
* @api private
*/
Client.prototype.setUpTimer = function() {
if (this.timer) {
clearTimeout(this.timer);
}

if (this.keepalive <= 0) {
return;
}
Expand All @@ -164,10 +162,14 @@ Client.prototype.setUpTimer = function() {

this.logger.debug({ timeout: timeout }, "setting keepalive timeout");

this.timer = setTimeout(function() {
that.logger.info("keepalive timeout");
that.onNonDisconnectClose();
}, timeout);
if( this.timer ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you write this one as if (this.timer)?

this.timer.reschedule( timeout );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this one as this.timer.reschedule(timeout);

} else {
this.timer = retimer(function keepaliveTimeout() {
that.logger.info("keepalive timeout");
that.onNonDisconnectClose();
}, timeout);
}
};

/**
Expand Down Expand Up @@ -567,7 +569,7 @@ Client.prototype.close = function(callback) {
that.logger.debug("closing client");

if (this.timer) {
clearTimeout(this.timer);
this.timer.clear();
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"msgpack5": "^1.3.0",
"pbkdf2-password": "^1.0.0",
"qlobber": "~0.5.0",
"retimer": "^1.0.1",
"shortid": "^2.1.3",
"st": "~0.5.1",
"uuid": "^2.0.1",
Expand Down