Navigation Menu

Skip to content

Commit

Permalink
Don't run callback twice
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 9, 2015
1 parent e521975 commit c0a1388
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/droonga-protocol/connection.js
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down

0 comments on commit c0a1388

Please sign in to comment.