From 6389c7e0ae3abc0c8433484712204ee6e3d1b8bb Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Mar 2016 09:28:41 +0000 Subject: [PATCH] use event listener to determine when the consumer has connected --- lib/kafka_ascoltatore.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/kafka_ascoltatore.js b/lib/kafka_ascoltatore.js index a42e110..fc6eca7 100644 --- a/lib/kafka_ascoltatore.js +++ b/lib/kafka_ascoltatore.js @@ -135,6 +135,7 @@ KafkaAscoltatore.prototype._startConn = function(cb) { var newcb = function(){ that._consumerStarting = false; util.wrap(cb)(); + that.emit("consumer.connected"); }; var connectionString = that._opts.connectionString || that._default_opts.connectionString; var clientId = that._opts.clientId || that._default_opts.clientId; @@ -210,7 +211,7 @@ KafkaAscoltatore.prototype.subscribe = function subscribe(topic, callback, done) var that = this; if(this._consumerStarting){ debug("waiting for startup before subscribing"); - setTimeout(function(){ that.subscribe(topic,callback,done); }, 500); + this.on("consumer.connected",function(){ that.subscribe(topic,callback,done); }); return; }