function writev(producer, topic, chunks, cb) {

  // @todo maybe a produce batch method?
  var doneCount = 0;
  var err = null;
  var chunk = null;

  function maybeDone(e) {
    if (e) {
      err = e;
    }
    doneCount ++;
    if (doneCount === chunks.length) {
      cb(err);
    }
  }

  function retry(restChunks) {
    // Poll for good measure
    producer.poll();

    // Just delay this thing a bit and pass the params
    // backpressure will get exerted this way.
    setTimeout(function() {
      writev(producer, topic, restChunks, cb);
    }, 500);
  }

  for (var i = 0; i < chunks.length; i++) {
    chunk = chunks[i];

    try {
      if (Buffer.isBuffer(chunk)) {
        producer.produce(topic, null, chunk, null);
      } else {
        producer.produce(chunk.topic, chunk.partition, chunk.value, chunk.key, chunk.timestamp, chunk.opaque, chunk.headers);
      }
      maybeDone();
    } catch (e) {
      if (ErrorCode.ERR__QUEUE_FULL === e.code) {
        retry(chunks.slice(i));
      } else {
        cb(e);
      }
      break;
    }
  }

}
Internal stream write method for ProducerStream when writing objects.

This method should never be called externally. It has some recursion to
handle cases where the producer is not yet connected.

@param  {object} message - Message to write.
@param  {string} encoding - Encoding for the buffer
@param  {Function} cb - Callback to call when the stream is done processing
the data.
@private
@see https://github.com/nodejs/node/blob/master/lib/fs.js#L1901