[Groonga-commit] droonga/express-droonga at c0a1388 [master] Don't run callback twice

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Apr 9 16:34:15 JST 2015


YUKI Hiroshi	2015-04-09 16:34:15 +0900 (Thu, 09 Apr 2015)

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

  Message:
    Don't run callback twice

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

  Modified: lib/droonga-protocol/connection.js (+7 -4)
===================================================================
--- lib/droonga-protocol/connection.js    2015-04-08 20:29:42 +0900 (0bad7b1)
+++ lib/droonga-protocol/connection.js    2015-04-09 16:34:15 +0900 (df33dde)
@@ -230,7 +230,9 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
     type:       type,
     body:       body
   };
+  var sendingMessages = { type: type };
   if (callback) {
+    sendingMessages.callback = callback;
     envelope.replyTo = from;
 
     var event = 'reply:' + id;
@@ -239,19 +241,20 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
       this._logger.debug('Connection.emitMessage.reply %d (%s):',
                          this._id, this.hostAndPort, errorCode);
       clearTimeout(timeoutId);
+      if (sendingMessages)
+        sendingMessages.callback = null;
       callback(errorCode, response);
     }).bind(this));
     options.timeout = toPositiveInteger(options.timeout) ||
                         DEFAULT_RESPONSE_TIMEOUT;
     timeoutId = setTimeout((function() {
       this.removeAllListeners(event);
+      if (sendingMessages)
+        sendingMessages.callback = null;
       callback(ERROR_GATEWAY_TIMEOUT, null);
     }).bind(this), options.timeout);
   }
-  this._sendingMessages[id] = {
-    type: type,
-    callback: callback
-  };
+  this._sendingMessages[id] = sendingMessages;
   this._sender.emit('message', envelope, options.emittedCallback);
   return envelope;
 };
-------------- next part --------------
HTML����������������������������...
Download 



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