[Groonga-commit] groonga/express-kotoumi [master] Accept more options for Connection#emitMessage

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Jan 29 15:19:59 JST 2013


YUKI Hiroshi	2013-01-29 15:19:59 +0900 (Tue, 29 Jan 2013)

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

  Log:
    Accept more options for Connection#emitMessage

  Modified files:
    lib/backend/connection.js

  Modified: lib/backend/connection.js (+10 -7)
===================================================================
--- lib/backend/connection.js    2013-01-29 14:50:41 +0900 (7d85ae1)
+++ lib/backend/connection.js    2013-01-29 15:19:59 +0900 (9431430)
@@ -107,7 +107,8 @@ function toPositiveInteger(number) {
   return Math.max(integer, 0);
 }
 
-Connection.prototype.emitMessage = function(type, body, callback, timeout) {
+Connection.prototype.emitMessage = function(type, body, options) {
+  options = timeout || {};
   var id = createId();
   var envelope = {
     id:         id,
@@ -117,23 +118,25 @@ Connection.prototype.emitMessage = function(type, body, callback, timeout) {
     type:       type,
     body:       body
   };
-  if (callback) {
+  if (options.callback) {
+    var callback = options.callback;
     var event = 'inReplyTo:' + id;
     this.once(event, callback);
-    timeout = toPositiveInteger(timeout);
-    if (timeout) {
+    options.timeout = toPositiveInteger(options.timeout);
+    if (options.timeout) {
       setTimeout((function() {
-        if (this.listeners(event)) {
+        if (this.listeners(event).length) {
           this.removeAllListeners(event);
           this._sender.removeAllListeners('error');
           callback(ERROR_GATEWAY_TIMEOUT, null);
         }
-      }).bind(this), timeout);
+      }).bind(this), options.timeout);
     }
   }
+  options.delay = toPositiveInteger(options.delay);
   setTimeout((function() {
     this._sendEnvelope(envelope);
-  }).bind(this), 0);
+  }).bind(this), options.delay);
   return envelope;
 };
 
-------------- next part --------------
HTML����������������������������...
Download 



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