lib/eventDispatcher.js
function(callback) {

    if (typeof this.publisher !== 'function') {
      var pubErrMsg = 'publisher not injected!';
      debug(pubErrMsg);
      if (callback) callback(new Error(pubErrMsg));
      return;
    }

    if (!this.store || typeof this.store.getUndispatchedEvents !== 'function'
                    || typeof this.store.setEventToDispatched !== 'function') {
      var storeErrMsg = 'store not injected!';
      debug(storeErrMsg);
      if (callback) callback(new Error(storeErrMsg))
      return;
    }

    var self = this;

    // Get all undispatched events from store and queue them
    // before all other events passed in by the addUndispatchedEvents function.
    this.store.getUndispatchedEvents(function(err, events) {

      if (err) {
        debug(err);
        if (callback) callback(err);
        return;
      }

      var triggered = false;
      if (events) {
        for (var i = 0, len = events.length; i < len; i++) {
          self.undispatchedEventsQueue.push(events[i]);
          // If there are a lot of events then we can hit issues with the call stack size when processing in one go
          triggered = false;
          if (i % 1000 === 0){
            triggered = true;
            trigger(self);
          }
        }
      }

      if (!triggered) {
        trigger(self);
      }

      if (callback) callback(null);
    });
  }
function(callback) {

    if (typeof this.publisher !== 'function') {
      var pubErrMsg = 'publisher not injected!';
      debug(pubErrMsg);
      if (callback) callback(new Error(pubErrMsg));
      return;
    }

    if (!this.store || typeof this.store.getUndispatchedEvents !== 'function'
                    || typeof this.store.setEventToDispatched !== 'function') {
      var storeErrMsg = 'store not injected!';
      debug(storeErrMsg);
      if (callback) callback(new Error(storeErrMsg))
      return;
    }

    var self = this;

    // Get all undispatched events from store and queue them
    // before all other events passed in by the addUndispatchedEvents function.
    this.store.getUndispatchedEvents(function(err, events) {

      if (err) {
        debug(err);
        if (callback) callback(err);
        return;
      }

      var triggered = false;
      if (events) {
        for (var i = 0, len = events.length; i < len; i++) {
          self.undispatchedEventsQueue.push(events[i]);
          // If there are a lot of events then we can hit issues with the call stack size when processing in one go
          triggered = false;
          if (i % 1000 === 0){
            triggered = true;
            trigger(self);
          }
        }
      }

      if (!triggered) {
        trigger(self);
      }

      if (callback) callback(null);
    });
  }
function ( callback ) { if ( typeof this . publisher !== 'function' ) { var pubErrMsg = 'publisher not injected!' ; debug ( pubErrMsg ) ; if ( callback ) callback ( new Error ( pubErrMsg ) ) ; return ; } if ( ! this . store || typeof this . store . getUndispatchedEvents !== 'function' || typeof this . store . setEventToDispatched !== 'function' ) { var storeErrMsg = 'store not injected!' ; debug ( storeErrMsg ) ; if ( callback ) callback ( new Error ( storeErrMsg ) ) return ; } var self = this ; // Get all undispatched events from store and queue them // before all other events passed in by the addUndispatchedEvents function. this . store . getUndispatchedEvents ( function ( err , events ) { if ( err ) { debug ( err ) ; if ( callback ) callback ( err ) ; return ; } var triggered = false ; if ( events ) { for ( var i = 0 , len = events . length ; i < len ; i ++ ) { self . undispatchedEventsQueue . push ( events [ i ] ) ; // If there are a lot of events then we can hit issues with the call stack size when processing in one go triggered = false ; if ( i % 1000 === 0 ) { triggered = true ; trigger ( self ) ; } } } if ( ! triggered ) { trigger ( self ) ; } if ( callback ) callback ( null ) ; } ) ; }
Starts the instance to publish all undispatched events.
@param callback the function that will be called when this action has finished
Starts the instance to publish all undispatched events .