limitd-client
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -31,3 +31,3 @@ var url = require('url'); | ||
} | ||
this.pending_requests = {}; | ||
this._options = _.extend({}, defaults, options); | ||
@@ -56,4 +56,6 @@ this.connect(done); | ||
.on('data', function (response) { | ||
client.emit('response', response); | ||
client.emit('response_' + response.request_id, response); | ||
var response_handler = client.pending_requests[response.request_id]; | ||
if (response_handler) { | ||
response_handler(response); | ||
} | ||
}); | ||
@@ -91,2 +93,3 @@ | ||
var options = this._options; | ||
var client = this; | ||
@@ -117,3 +120,5 @@ if (_callback && request.method !== RequestMessage.Method.WAIT) { | ||
this.once('response_' + request.id, function (response) { | ||
client.pending_requests[request.id] = function (response) { | ||
delete client.pending_requests[request.id]; | ||
if (response.type === ResponseMessage.Type.ERROR && | ||
@@ -123,4 +128,6 @@ response['.limitd.ErrorResponse.response'].type === ErrorResponse.Type.UNKNOWN_BUCKET_TYPE) { | ||
} | ||
callback(null, response['.limitd.TakeResponse.response'] || response['.limitd.PutResponse.response'] || response['.limitd.StatusResponse.response']); | ||
}); | ||
callback(null, response['.limitd.TakeResponse.response'] || | ||
response['.limitd.PutResponse.response'] || | ||
response['.limitd.StatusResponse.response'] ); | ||
}; | ||
}; | ||
@@ -127,0 +134,0 @@ |
{ | ||
"name": "limitd-client", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "limitd client for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
25078
444