[Groonga-commit] groonga/express-kotoumi [master] Report response timeout error even if no timeout is specified

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Jan 30 12:22:49 JST 2013


YUKI Hiroshi	2013-01-30 12:22:49 +0900 (Wed, 30 Jan 2013)

  New Revision: 442be1f20780bf51a4557f11200cdaa6044b7d0f
  https://github.com/groonga/express-kotoumi/commit/442be1f20780bf51a4557f11200cdaa6044b7d0f

  Log:
    Report response timeout error even if no timeout is specified

  Modified files:
    lib/backend/connection.js

  Modified: lib/backend/connection.js (+12 -10)
===================================================================
--- lib/backend/connection.js    2013-01-30 12:22:11 +0900 (8520698)
+++ lib/backend/connection.js    2013-01-30 12:22:49 +0900 (23fadb4)
@@ -27,6 +27,10 @@ var ERROR_GATEWAY_TIMEOUT =
       Connection.ERROR_GATEWAY_TIMEOUT =
         504;
 
+var DEFAULT_RESPONSE_TIMEOUT =
+      Connection.DEFAULT_RESPONSE_TIMEOUT =
+        60 * 1000;
+
 function Connection(params) {
   this._params = params || {};
   this._init();
@@ -118,16 +122,14 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
   if (callback) {
     var event = 'inReplyTo:' + id;
     this.once(event, callback);
-    options.timeout = toPositiveInteger(options.timeout);
-    if (options.timeout) {
-      setTimeout((function() {
-        if (this.listeners(event).length) {
-          this.removeAllListeners(event);
-          this._sender.removeAllListeners('error');
-          callback(ERROR_GATEWAY_TIMEOUT, null);
-        }
-      }).bind(this), options.timeout);
-    }
+    options.timeout = toPositiveInteger(options.timeout) ||
+                        DEFAULT_RESPONSE_TIMEOUT;
+    setTimeout((function() {
+      if (this.listeners(event).length) {
+        this.removeAllListeners(event);
+        callback(ERROR_GATEWAY_TIMEOUT, null);
+      }
+    }).bind(this), options.timeout);
   }
   this._sender.emit('message', envelope);
   return envelope;
-------------- next part --------------
HTML����������������������������...
Download 



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