Navigation Menu

Skip to content

Commit

Permalink
Don't timeout emitMessage if negative timeout is given
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 20, 2015
1 parent 6356609 commit 929a2e8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/droonga-protocol/connection.js
Expand Up @@ -188,15 +188,15 @@ function getCurrentTime() {
return isoStringWithMicroseconds;
}

function toPositiveInteger(number) {
function toInteger(number) {
if (!number)
return 0;

var integer = parseInt(number);
if (isNaN(integer))
return 0;

return Math.max(integer, 0);
return integer;
}

Connection.prototype.emitMessage = function(type, body, callback, options) {
Expand Down Expand Up @@ -242,7 +242,8 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
this.once(event, (function(errorCode, response) {
this._logger.trace('Connection.emitMessage.reply %d (%s):',
this._id, this.hostAndPort, errorCode);
clearTimeout(timeoutId);
if (timeoutId)
clearTimeout(timeoutId);
if (sendingMessages)
sendingMessages.callback = null;
if (!callback)
Expand All @@ -255,8 +256,9 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
this._logger.error(error);
}
}).bind(this));
options.timeout = toPositiveInteger(options.timeout) ||
options.timeout = toInteger(options.timeout) ||
DEFAULT_RESPONSE_TIMEOUT;
if (options.timeout > -1) {
timeoutId = setTimeout((function() {
this.removeAllListeners(event);
if (sendingMessages)
Expand All @@ -271,6 +273,7 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
this._logger.error(error);
}
}).bind(this), options.timeout);
}
}
this._sendingMessages[id] = sendingMessages;
this._sender.emit('message', envelope, options.emittedCallback);
Expand Down

0 comments on commit 929a2e8

Please sign in to comment.