[Groonga-commit] droonga/express-droonga at 929a2e8 [master] Don't timeout emitMessage if negative timeout is given

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Apr 20 11:39:15 JST 2015


YUKI Hiroshi	2015-04-20 11:39:15 +0900 (Mon, 20 Apr 2015)

  New Revision: 929a2e83fb48fa50bfc884942e82426a6b61c48d
  https://github.com/droonga/express-droonga/commit/929a2e83fb48fa50bfc884942e82426a6b61c48d

  Message:
    Don't timeout emitMessage if negative timeout is given

  Modified files:
    lib/droonga-protocol/connection.js

  Modified: lib/droonga-protocol/connection.js (+7 -4)
===================================================================
--- lib/droonga-protocol/connection.js    2015-04-20 11:24:24 +0900 (4e8c1dd)
+++ lib/droonga-protocol/connection.js    2015-04-20 11:39:15 +0900 (cc4ac61)
@@ -188,7 +188,7 @@ function getCurrentTime() {
   return isoStringWithMicroseconds;
 }
 
-function toPositiveInteger(number) {
+function toInteger(number) {
   if (!number)
     return 0;
 
@@ -196,7 +196,7 @@ function toPositiveInteger(number) {
   if (isNaN(integer))
     return 0;
 
-  return Math.max(integer, 0);
+  return integer;
 }
 
 Connection.prototype.emitMessage = function(type, body, callback, options) {
@@ -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)
@@ -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)
@@ -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);
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index