YUKI Hiroshi
null+****@clear*****
Fri Apr 17 23:14:16 JST 2015
YUKI Hiroshi 2015-04-17 23:14:16 +0900 (Fri, 17 Apr 2015) New Revision: d10a86ea311296608187aaa39ecfc2c5d311026f https://github.com/droonga/express-droonga/commit/d10a86ea311296608187aaa39ecfc2c5d311026f Message: Suppress errors when callback functions is called twice or more Modified files: lib/droonga-protocol/connection.js Modified: lib/droonga-protocol/connection.js (+19 -2) =================================================================== --- lib/droonga-protocol/connection.js 2015-04-17 22:55:16 +0900 (b3ce284) +++ lib/droonga-protocol/connection.js 2015-04-17 23:14:16 +0900 (4e8c1dd) @@ -245,7 +245,15 @@ Connection.prototype.emitMessage = function(type, body, callback, options) { clearTimeout(timeoutId); if (sendingMessages) sendingMessages.callback = null; - callback(errorCode, response); + if (!callback) + return; + try { + callback(errorCode, response); + callback = null; + } + catch(error) { + this._logger.error(error); + } }).bind(this)); options.timeout = toPositiveInteger(options.timeout) || DEFAULT_RESPONSE_TIMEOUT; @@ -253,7 +261,15 @@ Connection.prototype.emitMessage = function(type, body, callback, options) { this.removeAllListeners(event); if (sendingMessages) sendingMessages.callback = null; - callback(ERROR_GATEWAY_TIMEOUT, null); + if (!callback) + return; + try { + callback(ERROR_GATEWAY_TIMEOUT, null); + callback = null; + } + catch(error) { + this._logger.error(error); + } }).bind(this), options.timeout); } this._sendingMessages[id] = sendingMessages; @@ -291,6 +307,7 @@ Connection.prototype.close = function() { if (typeof callback == 'function') { try { callback(ERROR_SERVICE_UNAVAILABLE, null); + message.callback = callback = null; } catch(error) { this._logger.error(error) -------------- next part -------------- HTML����������������������������...Download