Skip to content
Browse files

Update README and add new event for batch requests

  • Loading branch information...
1 parent 2c05c0d commit 79c0168fd686bcc80f8cc64ea45192c2642773e8 @tedeh committed Dec 30, 2012
Showing with 6 additions and 3 deletions.
  1. +2 −1 README.md
  2. +4 −2 lib/server.js
View
3 README.md
@@ -332,8 +332,9 @@ Every request to `add` on the public server will now relay the request to the pr
In addition to events that are specific to a certain interface, all servers will emit the following events:
-* `request` Emitted when the server receives an interpretable request. First argument is the request object.
+* `request` Emitted when the server receives an interpretable (non-batch) request. First argument is the request object.
* `response` Emitted when the server is returning a response. First argument is the request object, the second is the response object.
+* `batch` Emitted when the server receives a batch request. First argument is an array of requests. Will emit `request` for each interpretable request in the batch.
#### Errors
View
6 lib/server.js
@@ -173,8 +173,6 @@ Server.prototype.error = function(code, message, data) {
Server.prototype.call = function(request, originalCallback) {
var self = this;
- this.emit('request', request);
-
if(typeof(originalCallback) !== 'function') originalCallback = function() {};
// compose the callback so that we may emit an event on every response
@@ -203,6 +201,8 @@ Server.prototype.call = function(request, originalCallback) {
return this._batch(request, callback);
}
+ this.emit('request', request);
+
// is the request valid?
if(!isValidRequest(request)) {
return callback(utils.response(this.error(Server.errors.INVALID_REQUEST)));
@@ -271,6 +271,8 @@ Server.prototype._batch = function(requests, callback) {
var responses = [];
+ this.emit('batch', requests);
+
/**
* @ignore
*/

0 comments on commit 79c0168

Please sign in to comment.
Something went wrong with that request. Please try again.