[Groonga-commit] groonga/express-kotoumi [master] give the callback function for Connection#emitMessage as the third argument instead of a part of the option

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Jan 29 15:32:44 JST 2013


YUKI Hiroshi	2013-01-29 15:32:44 +0900 (Tue, 29 Jan 2013)

  New Revision: 71bf2d0bddd9be8e2a42f5c0c4504e27433cba49
  https://github.com/groonga/express-kotoumi/commit/71bf2d0bddd9be8e2a42f5c0c4504e27433cba49

  Log:
    give the callback function for Connection#emitMessage as the third argument instead of a part of the option

  Modified files:
    lib/backend/connection.js
    lib/frontend/rest-handler.js
    test/backend-connection.test.js
    test/frontend-rest-handler.test.js

  Modified: lib/backend/connection.js (+2 -3)
===================================================================
--- lib/backend/connection.js    2013-01-29 15:23:32 +0900 (5bf3703)
+++ lib/backend/connection.js    2013-01-29 15:32:44 +0900 (b31b923)
@@ -107,7 +107,7 @@ function toPositiveInteger(number) {
   return Math.max(integer, 0);
 }
 
-Connection.prototype.emitMessage = function(type, body, options) {
+Connection.prototype.emitMessage = function(type, body, callback, options) {
   options = options || {};
   var id = createId();
   var envelope = {
@@ -118,8 +118,7 @@ Connection.prototype.emitMessage = function(type, body, options) {
     type:       type,
     body:       body
   };
-  if (options.callback) {
-    var callback = options.callback;
+  if (callback) {
     var event = 'inReplyTo:' + id;
     this.once(event, callback);
     options.timeout = toPositiveInteger(options.timeout);

  Modified: lib/frontend/rest-handler.js (+6 -4)
===================================================================
--- lib/frontend/rest-handler.js    2013-01-29 15:23:32 +0900 (9d59504)
+++ lib/frontend/rest-handler.js    2013-01-29 15:32:44 +0900 (27cf394)
@@ -9,8 +9,10 @@ function createHandler(type,
   return (function(request, response) {
     var message = requestBuilder(request);
     var timeout = message.timeout || null;
-    connection.emitMessage(type, message, {
-      callback: function(error, responseMessage) {
+    connection.emitMessage(
+      type,
+      message,
+      function(error, responseMessage) {
         if (error) {
           var body = responseMessage && responseMessage.body || null;
           response.contentType('application/json');
@@ -21,8 +23,8 @@ function createHandler(type,
           response.send(body, 200);
         }
       },
-      timeout: timeout
-    });
+      { timeout: timeout }
+    );
   });
 }
 exports.createHandler = createHandler;

  Modified: test/backend-connection.test.js (+7 -14)
===================================================================
--- test/backend-connection.test.js    2013-01-29 15:23:32 +0900 (ae61a0b)
+++ test/backend-connection.test.js    2013-01-29 15:32:44 +0900 (c36fe06)
@@ -194,9 +194,7 @@ suite('Connection, basic features', function() {
     Deferred
       .wait(0.01)
       .next(function() {
-        message = connection.emitMessage('testRequest', { command: 'foobar' }, {
-          callback: callback
-        });
+        message = connection.emitMessage('testRequest', { command: 'foobar' }, callback);
         assert.envelopeEqual(message,
                              createExpectedEnvelope('testRequest', { command: 'foobar' }));
       })
@@ -234,9 +232,7 @@ suite('Connection, basic features', function() {
     Deferred
       .wait(0.01)
       .next(function() {
-        message = connection.emitMessage('testRequest', { command: 'foobar' }, {
-          callback: callback
-        });
+        message = connection.emitMessage('testRequest', { command: 'foobar' }, callback);
         assert.envelopeEqual(message,
                              createExpectedEnvelope('testRequest', { command: 'foobar' }));
       })
@@ -268,9 +264,8 @@ suite('Connection, basic features', function() {
     Deferred
       .wait(0.01)
       .next(function() {
-        message = connection.emitMessage('testRequest', { command: 'foobar' }, {
-          callback: callback,
-          timeout:  1000
+        message = connection.emitMessage('testRequest', { command: 'foobar' }, callback, {
+          timeout: 1000
         });
         assert.envelopeEqual(message,
                              createExpectedEnvelope('testRequest', { command: 'foobar' }));
@@ -304,8 +299,7 @@ suite('Connection, basic features', function() {
       .wait(0.01)
       .next(function() {
         callback.takes(Connection.ERROR_GATEWAY_TIMEOUT, null);
-        message = connection.emitMessage('testRequest', { command: 'foobar' }, {
-          callback: callback,
+        message = connection.emitMessage('testRequest', { command: 'foobar' }, callback, {
           timeout:  1,
           delay:    1000
         });
@@ -338,9 +332,8 @@ suite('Connection, basic features', function() {
     Deferred
       .wait(0.01)
       .next(function() {
-        message = connection.emitMessage('testRequest', { command: 'foobar' }, {
-          callback: callback,
-          timeout:  -1
+        message = connection.emitMessage('testRequest', { command: 'foobar' }, callback, {
+          timeout: -1
         });
         assert.envelopeEqual(message,
                              createExpectedEnvelope('testRequest', { command: 'foobar' }));

  Modified: test/frontend-rest-handler.test.js (+4 -3)
===================================================================
--- test/frontend-rest-handler.test.js    2013-01-29 15:23:32 +0900 (3a35674)
+++ test/frontend-rest-handler.test.js    2013-01-29 15:32:44 +0900 (bd76e6e)
@@ -94,7 +94,7 @@ suite('REST API', function() {
     var onReceive = {};
     var connection = nodemock
           .mock('emitMessage')
-            .takes('search', { requestMessage: true }, function() {}, null)
+            .takes('search', { requestMessage: true }, function() {}, {})
             .ctrl(2, onReceive);
     var handler = restHandler
           .createHandler('search',
@@ -129,11 +129,12 @@ suite('REST API', function() {
     test('search', function(done) {
       var receiverCallback = {};
       var connection = {
-            emitMessage: function(type, message, callback) {
+            emitMessage: function(type, message, callback, options) {
               this.emitMessageCalledArguments.push({
                 type:     type,
                 message:  message,
-                callback: callback
+                callback: callback,
+                options:  options
               });
             },
             emitMessageCalledArguments: []
-------------- next part --------------
HTML����������������������������...
下載 



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