lib/revisionGuard.js
function (evt, revInStore, callback) {
    var evtId = dotty.get(evt, this.definition.id);
    var revInEvt = dotty.get(evt, this.definition.revision);

    var self = this;

    var concatenatedId = this.getConcatenatedId(evt);

    this.store.set(concatenatedId, revInEvt + 1, revInStore, function (err) {
      if (err) {
        debug(err);
        if (err instanceof ConcurrencyError) {
          var retryIn = randomBetween(0, self.options.retryOnConcurrencyTimeout || 800);
          debug('retry in ' + retryIn + 'ms for [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);
          setTimeout(function() {
            self.guard(evt, callback);
          }, retryIn);
          return;
        }

        return callback(err);
      }

      self.store.saveLastEvent(evt, function (err) {
        if (err) {
          debug('error while saving last event');
          debug(err);
        }
      });

      self.queue.remove(concatenatedId, evtId);
      callback(null);

      var pendingEvents = self.queue.get(concatenatedId);
      if (!pendingEvents || pendingEvents.length === 0) return debug('no other pending event found [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);

      var nextEvent = _.find(pendingEvents, function (e) {
        var revInNextEvt = dotty.get(e.payload, self.definition.revision);
        return revInNextEvt === revInEvt + 1;
      });

      if (!nextEvent) return debug('no next pending event found [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);

      debug('found next pending event => guard [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);
      self.guard(nextEvent.payload, nextEvent.callback);
    });
  }
function (evt, revInStore, callback) {
    var evtId = dotty.get(evt, this.definition.id);
    var revInEvt = dotty.get(evt, this.definition.revision);

    var self = this;

    var concatenatedId = this.getConcatenatedId(evt);

    this.store.set(concatenatedId, revInEvt + 1, revInStore, function (err) {
      if (err) {
        debug(err);
        if (err instanceof ConcurrencyError) {
          var retryIn = randomBetween(0, self.options.retryOnConcurrencyTimeout || 800);
          debug('retry in ' + retryIn + 'ms for [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);
          setTimeout(function() {
            self.guard(evt, callback);
          }, retryIn);
          return;
        }

        return callback(err);
      }

      self.store.saveLastEvent(evt, function (err) {
        if (err) {
          debug('error while saving last event');
          debug(err);
        }
      });

      self.queue.remove(concatenatedId, evtId);
      callback(null);

      var pendingEvents = self.queue.get(concatenatedId);
      if (!pendingEvents || pendingEvents.length === 0) return debug('no other pending event found [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);

      var nextEvent = _.find(pendingEvents, function (e) {
        var revInNextEvt = dotty.get(e.payload, self.definition.revision);
        return revInNextEvt === revInEvt + 1;
      });

      if (!nextEvent) return debug('no next pending event found [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);

      debug('found next pending event => guard [concatenatedId]=' + concatenatedId + ', [revInStore]=' + (revInStore || 'null') + ', [revInEvt]=' + revInEvt);
      self.guard(nextEvent.payload, nextEvent.callback);
    });
  }
function ( evt , revInStore , callback ) { var evtId = dotty . get ( evt , this . definition . id ) ; var revInEvt = dotty . get ( evt , this . definition . revision ) ; var self = this ; var concatenatedId = this . getConcatenatedId ( evt ) ; this . store . set ( concatenatedId , revInEvt + 1 , revInStore , function ( err ) { if ( err ) { debug ( err ) ; if ( err instanceof ConcurrencyError ) { var retryIn = randomBetween ( 0 , self . options . retryOnConcurrencyTimeout || 800 ) ; debug ( 'retry in ' + retryIn + 'ms for [concatenatedId]=' + concatenatedId + ', [revInStore]=' + ( revInStore || 'null' ) + ', [revInEvt]=' + revInEvt ) ; setTimeout ( function ( ) { self . guard ( evt , callback ) ; } , retryIn ) ; return ; } return callback ( err ) ; } self . store . saveLastEvent ( evt , function ( err ) { if ( err ) { debug ( 'error while saving last event' ) ; debug ( err ) ; } } ) ; self . queue . remove ( concatenatedId , evtId ) ; callback ( null ) ; var pendingEvents = self . queue . get ( concatenatedId ) ; if ( ! pendingEvents || pendingEvents . length === 0 ) return debug ( 'no other pending event found [concatenatedId]=' + concatenatedId + ', [revInStore]=' + ( revInStore || 'null' ) + ', [revInEvt]=' + revInEvt ) ; var nextEvent = _ . find ( pendingEvents , function ( e ) { var revInNextEvt = dotty . get ( e . payload , self . definition . revision ) ; return revInNextEvt === revInEvt + 1 ; } ) ; if ( ! nextEvent ) return debug ( 'no next pending event found [concatenatedId]=' + concatenatedId + ', [revInStore]=' + ( revInStore || 'null' ) + ', [revInEvt]=' + revInEvt ) ; debug ( 'found next pending event => guard [concatenatedId]=' + concatenatedId + ', [revInStore]=' + ( revInStore || 'null' ) + ', [revInEvt]=' + revInEvt ) ; self . guard ( nextEvent . payload , nextEvent . callback ) ; } ) ; }
Finishes the guard stuff and save the new revision to store.
@param {Object}   evt        The event object.
@param {Number}   revInStore The actual revision number in store.
@param {Function} callback   The function, that will be called when this action is completed.
`function(err){}`
Finishes the guard stuff and save the new revision to store .