code: function doNextCompaction(self) {
    var task = self._compactionQueue[0];
    var opts = task.opts;
    var callback = task.callback;
    self.get('_local/compaction').catch(function () {
      return false;
    }).then(function (doc) {
      if (doc && doc.last_seq) {
        opts.last_seq = doc.last_seq;
      }
      self._compact(opts, function (err, res) {
        /* istanbul ignore if */
        if (err) {
          callback(err);
        } else {
          callback(null, res);
        }
        pouchdbUtils.nextTick(function () {
          self._compactionQueue.shift();
          if (self._compactionQueue.length) {
            doNextCompaction(self);
          }
        });
      });
    });
  }
docs: all compaction is done in a queue, to avoid attaching too many listeners at once