Returns a Promise of a promisified and connected rdkafka.KafkaConsumer.

@param  {Object} kafkaConfig
@return {Promise<KafkaConsumer>} Promisified KafkaConsumer
482728
function createKafkaConsumerAsync(kafkaConfig) {
    let topicConfig = {};
    if ('default_topic_config' in kafkaConfig) {
        topicConfig = kafkaConfig.default_topic_config;
        delete kafkaConfig.default_topic_config;
    }

    const consumer = P.promisifyAll(
        new kafka.KafkaConsumer(kafkaConfig, topicConfig)
    );

    return consumer.connectAsync(undefined)
    .thenReturn(consumer);
}
713602
function pool(promiseFactories, limit) {
  return new Promise(function (resolve, reject) {
    var running = 0;
    var current = 0;
    var done = 0;
    var len = promiseFactories.length;
    var err;

    function runNext() {
      running++;
      promiseFactories[current++]().then(onSuccess, onError);
    }

    function doNext() {
      if (++done === len) {
        /* istanbul ignore if */
        if (err) {
          reject(err);
        } else {
          resolve();
        }
      } else {
        runNextBatch();
      }
    }

    function onSuccess() {
      running--;
      doNext();
    }

    /* istanbul ignore next */
    function onError(thisErr) {
      running--;
      err = err || thisErr;
      doNext();
    }

    function runNextBatch() {
      while (running < limit && current < len) {
        runNext();
      }
    }

    runNextBatch();
  });
}
335953
function(fn) {
  if (promisify.isPromise(fn))
    return fn;
  if (typeof fn !== 'function')
    return promisify.Promise.resolve(fn);
  return new Promise((resolve, reject) => {
    try {
      const o = fn();
      if (promisify.isPromise(o)) {
        o.then(v => resolve(v))
            .catch((e) => reject(e));
      } else resolve(o);
    } catch (e) {
      reject(e);
    }
  });
}
516732
function Deferred(opts){
 	/**
	 * @define {object} Collection of public methods.
	 */
	var self = {};

	/**
	 * @define {object} options for the constructor 
	 */
	var opts = opts || {};

	/**
	 * @define {object} A promise object that will be returned
	 */
	var promise = {};

	/**
	 * @define {object} Event system for controlling events
	 */
	var event = Event();
	
	/**
	 * Promise then method
	 * This is for chaining promis callbacks
	 * @example promiseFunction().then(
	 * function(){ // success }, 
	 * function(){ // rejected }, 
	 * function(){ // notify } 
	 * ).then( ... );
	 * @param {function} sucess Success callback
	 * @param {function} reject Reject callback
	 * @param {function} notify notify callback
	 * @return {object} Returns the promise object
	 */
	function promiseThen(success, reject, notify){
		/**
		 * @define {object} Return a new promise
		 */
		var def = Deferred();

		/**
		 * Resolved promise
		 * @example example
		 * @param {string} A string key for the event system
		 * @param {function} A callback when event is triggered
		 * @return {object} Returns promise object
		 */
		event.on('resolve', function(){ 
			/**
			 * If the success callback returns a promise
			 * then resolve/reject/notify that returned promise
			 */
			var promise = success();
			if(!promise) return;
			promise.success(function(){
				/** handle the returned deferred object */
				def.resolve();
			});
			promise.error(function(){
				def.reject();
			});
			promise.notify(function(){
				def.notify();
			});
		});

		/**
		 * If promise is rejected/notify trigger the callback
		 */
		event.on('reject', function(){ 
			if(reject) reject();
		});

		event.on('notify', function(){ 
			if(notify) notify();
		});

		/**
		 * @return {object} Returns a promise object
		 */
		return def.promise; 
	}

	/**
	 * Promise methods
	 * @example promise.then( //new promise ).then(...)
	 * @example promise.success(...).error(...).notify(...)
	 * @param {function} callback A callback for the promise
	 * @return {object} Return the promise
	 */
	function promiseSuccess(callback){
		event.on('resolve', callback);
		return promise;
	}

	function promiseError(callback){
		event.on('reject', callback);
		return promise;
	}

	function promiseNotified(callback){
		event.on('notify', callback);
		return promise;
	}

	/**
	 * Deferred methods to trigger the promise
	 * @example def.resolve(args)
	 * @example def.reject(args)
	 * @example def.notify(args)
	 */
	function resolve(){
		var args = Array.prototype.slice.call(arguments);
		event.trigger('resolve', args);
	}

	function reject(){
		var args = Array.prototype.slice.call(arguments);
		event.trigger('reject', args);	
	}

	function notify(){
		var args = Array.prototype.slice.call(arguments);
		event.trigger('notify', args);		
	}

	/**
	 * Add the promise methods to the promise object
	 */
	promise.then = promiseThen;
	promise.success = promiseSuccess;
	promise.error = promiseError;
	promise.notify = promiseNotified;

	/**
	 * The promise object
	 * @public {object}
	 */
	self.promise = promise;

	/**
	 * Deferred public methods	
	 * @public {function}
	 */
	self.resolve = resolve;
	self.reject = reject;
	self.notify = notify;

	/**
	 * @return {object} return public methos
	 */
	return self;
}
1179175
private KafkaConsumer<String, byte[]> _getConsumer(String topic, boolean autoCommitOffsets) {
        KafkaConsumer<String, byte[]> consumer = topicConsumers.get(topic);
        if (consumer == null) {
            consumer = KafkaHelper.createKafkaConsumer(bootstrapServers, consumerGroupId,
                    consumeFromBeginning, autoCommitOffsets, consumerProperties);
            KafkaConsumer<String, byte[]> existingConsumer = topicConsumers.putIfAbsent(topic,
                    consumer);
            if (existingConsumer != null) {
                consumer.close();
                consumer = existingConsumer;
            } else {
                _checkAndSubscribe(consumer, topic);
            }
        }
        return consumer;
    }
676609
function promiseTry(callback) {
  try {
    const maybePromise = callback();

    if (isPromise(maybePromise)) {
      return maybePromise;
    } else {
      return Promise.resolve(maybePromise);
    }
  } catch (err) {
    return Promise.reject(err);
  }
}
1274558
function() {
    return new Promise((resolve, reject) => {
      let instance;
      if (this.modelElement.name === this.node.getName()) {
        instance = this.node;
      } else {
        instance = this.mapper.getObject(this.modelElement.path());
      }

      if (instance) {
        if (instance.isStarted()) {
          instance.__update__(timesUp('update(...)', 30000, (err) => {
            if (err) {
              this.log.error('Unable to update ' + instance.getPath());
              reject(err);
            } else {
              this.log.debug(instance.getPath());
              this.node.kCore.emitter.emit('instanceUpdated', instance);
              resolve();
            }
          }));
        }
      } else {
        reject(new Error(this.toString() + ' error: unable to update instance ' + this.modelElement.name));
      }
    });
  }
21774
@Override
    public <T> Promise<T> toPromise(Consumer<Handler<AsyncResult<T>>> consumer) {
        Deferred<T> d = when.defer();
        consumer.accept(toHandler(d));
        return d.getPromise();
    }
1106438
function promisify(err, value, callback) {
  if (err) { throw err; }
  if (isPromiseLike(value)) {
    value.then(function(v) {
      callback(null, v);
    }, function(err) {
      callback(err);
    });
  } else {
    callback(null, value);
  }
}
592077
function sync(fn) {
  return function(done) {
    var res = isGenerator(fn) ? co(fn) : fn(done);
    if (isPromise(res)) {
      res.then(function(){ done(); }, done);
    } else {
      fn.length || done();
    }
  };
}
707324
function () {
    return new Promise((resolve, reject) => {
      if (this.modelElement.host && this.modelElement.host.name === this.node.getName()) {
        // this element is a subNode to this.node
        this.node.removeSubNode(this.modelElement, timesUp(this.node.getName() + '.removeSubNode(...)', 30000, (err) => {
          if (!err) {
            this.log.debug(this.node.getName() + ' removed ' + this.modelElement.name);
            // TODO ? add eventEmitter hook for subNode too ?
          }
          reject(err);
        }));
        return;

      } else {
        const instance = this.mapper.getObject(this.modelElement.path());
        if (instance) {
          if (this.modelElement.getRefInParent() === 'components') {
            // check if there is binding to remove in current channels
            this.node.kCore.currentModel.mBindings.array.forEach((binding) => {
              if (binding.port && binding.port.eContainer() && binding.port.eContainer().path() === instance.path) {
                const chan = this.mapper.getObject(binding.hub.path());
                const port = this.mapper.getObject(binding.port.path());
                if (chan && port && binding.port.getRefInParent() === 'provided') {
                  // unload old binding in channel instance
                  chan.removeInternalInputPort(port);
                }
              }
            });
          }
          instance.__destruct__();
          this.mapper.removeEntry(this.modelElement.path());
          this.log.debug(instance.getName() + ' ' + this.modelElement.typeDefinition.path());
          this.node.kCore.emitter.emit('instanceRemoved', instance);
          resolve();
          return;
        }
      }
      resolve();
    });
  }
941605
function makePromise(requestInstance, promiseFactoryFn) {

  // Resolver function wich assigns the promise (resolve, reject) functions
  // to the requestInstance
  function Resolver(resolve, reject) {
    this._resolve = resolve;
    this._reject = reject;
  }

  return promiseFactoryFn(Resolver.bind(requestInstance));
}
514009
function promiseChain (cb) {
  var steps = []
    , vals = []
    , context = this
  function go () {
    var step = steps.shift()
    if (!step) return cb()
    try { step[0].apply(context, step[1]) }
    catch (ex) { cb(ex) }
  }
  return function pc (fn, args, success) {
    if (arguments.length === 0) return go()
    // add the step
    steps.push
      ( [ fn
        , (args || []).concat([ function (er) {
            if (er) return cb(er)
            var a = Array.prototype.slice.call(arguments, 1)
            try { success && success.apply(context, a) }
            catch (ex) { return cb(ex) }
            go()
          }])
        ]
      )
    return pc
  }
}
372906
function (k, v) {
        promiseChain = promiseChain.then(function() {
          return self.set(k, v);
        }).catch(function (e) {
          // console.log("Caught error setting {", k, ":", v, "}: ", e);
          self.emit('error', e);
          return Q.fcall(function () {});
        });
      }
658347
function() {
    _cbt =  require('./cbt')();
    _options = options || {};

    // apply defaults
    // the min bytes of an incoming reply
    _options.minBytes = _options.minBytes || 1;

    // the max bytes of an incoming reply
    _options.maxBytes = _options.maxBytes || 1024 * 1024;

    // the group the client will join when using `.connect()`
    _options.group = _options.group || 'kafkaesqueGroup';

    // the clientID when connecting to kafka
    _options.clientId = _options.clientId || 'kafkaesque' + Math.floor(Math.random() * 100000000);

    // the array of brokers
    _options.brokers = _options.brokers || [{host: 'localhost', port: 9092}];

    // the amount of time it should take for this clients session within the group
    // to timeout
    _options.sessionTimeout = _options.sessionTimeout || 6000;

    // the amount of time to take to emit a heartbeat msg
    _options.heartbeat = _options.heartbeat || 2500;

    // the default amount of time that the kafka broker shoudl wait to send
    // a reply to a fetch request if the fetch reply is smaller than the minBytes
    _options.maxWait = _options.maxWait || 5000;

    _brokers = {};
    _topics = {};
    _groupMemberId = '';
    _groupGeneration = 0;
    _.each(_options.brokers, function(broker) {
      broker = {
        host: broker.host,
        port: broker.port,
        maxBytes: _options.maxBytes,
        minBytes: _options.minBytes,
        clientId: _options.clientId
      };

      _brokers[_makeBrokerKey(broker)] = api(broker);
    });

    _metaBroker = _brokers[_makeBrokerKey(_options.brokers[0])];
  }
933538
IterableOfProtosFluentAssertion<M> usingConfig(FluentEqualityConfig newConfig) {
    Subject.Factory<IterableOfMessagesSubject<M>, Iterable<M>> factory =
        iterableOfMessages(newConfig);
    IterableOfMessagesSubject<M> newSubject = check().about(factory).that(actual());
    if (internalCustomName() != null) {
      newSubject = newSubject.named(internalCustomName());
    }
    return new IterableOfProtosFluentAssertionImpl<M>(newSubject);
  }
1128877
function promiseWrap(x) {
  if(x.then && typeof x.then === "function") {
    return x;    
  }
  var deferred = q.defer();
  deferred.resolve(x);
  return deferred.promise;
}