lib/pm.js
function (callback) {

    var self = this;

    var warnings = null;

    async.series([
      // load saga files...
      function (callback) {
        if (self.options.sagaPath === '') {
          self.sagas = {};
          debug('empty sagaPath defined so no sagas will be loaded...');
          return callback(null);
        }
        debug('load saga files...');
        self.structureLoader(self.options.sagaPath, function (err, sagas, warns) {
          if (err) {
            return callback(err);
          }
          warnings = warns;
          self.sagas = attachLookupFunctions(sagas);
          callback(null);
        });
      },

      // prepare infrastructure...
      function (callback) {
        debug('prepare infrastructure...');
        async.parallel([

          // prepare sagaStore...
          function (callback) {
            debug('prepare sagaStore...');

            self.sagaStore.on('connect', function () {
              self.emit('connect');
            });

            self.sagaStore.on('disconnect', function () {
              self.emit('disconnect');
            });

            self.sagaStore.connect(callback);
          },

          // prepare revisionGuard...
          function (callback) {
            debug('prepare revisionGuard...');
            if (!self.revisionGuardStore) {
              return callback(null);
            }

            self.revisionGuardStore.on('connect', function () {
              self.emit('connect');
            });

            self.revisionGuardStore.on('disconnect', function () {
              self.emit('disconnect');
            });

            self.revisionGuardStore.connect(callback);
          }
        ], callback);
      },

      // inject all needed dependencies...
      function (callback) {
        debug('inject all needed dependencies...');

        if (self.revisionGuardStore) {
          self.revisionGuard = new RevisionGuard(self.revisionGuardStore, self.options.revisionGuard);
          self.revisionGuard.onEventMissing(function (info, evt) {
            self.onEventMissingHandle(info, evt);
          });
        }

        if (self.options.sagaPath !== '') {
          self.eventDispatcher = new EventDispatcher(self.sagas, self.definitions.event);
          self.sagas.defineOptions({}) // options???
            .defineCommand(self.definitions.command)
            .defineEvent(self.definitions.event)
            .idGenerator(self.getNewId)
            .useSagaStore(self.sagaStore);
        }

        if (self.revisionGuardStore) {
          self.revisionGuard.defineEvent(self.definitions.event);
        }

        callback(null);
      }
    ], function (err) {
      if (err) {
        debug(err);
      }
      if (callback) { callback(err, warnings); }
    });
  }
function (callback) {

    var self = this;

    var warnings = null;

    async.series([
      // load saga files...
      function (callback) {
        if (self.options.sagaPath === '') {
          self.sagas = {};
          debug('empty sagaPath defined so no sagas will be loaded...');
          return callback(null);
        }
        debug('load saga files...');
        self.structureLoader(self.options.sagaPath, function (err, sagas, warns) {
          if (err) {
            return callback(err);
          }
          warnings = warns;
          self.sagas = attachLookupFunctions(sagas);
          callback(null);
        });
      },

      // prepare infrastructure...
      function (callback) {
        debug('prepare infrastructure...');
        async.parallel([

          // prepare sagaStore...
          function (callback) {
            debug('prepare sagaStore...');

            self.sagaStore.on('connect', function () {
              self.emit('connect');
            });

            self.sagaStore.on('disconnect', function () {
              self.emit('disconnect');
            });

            self.sagaStore.connect(callback);
          },

          // prepare revisionGuard...
          function (callback) {
            debug('prepare revisionGuard...');
            if (!self.revisionGuardStore) {
              return callback(null);
            }

            self.revisionGuardStore.on('connect', function () {
              self.emit('connect');
            });

            self.revisionGuardStore.on('disconnect', function () {
              self.emit('disconnect');
            });

            self.revisionGuardStore.connect(callback);
          }
        ], callback);
      },

      // inject all needed dependencies...
      function (callback) {
        debug('inject all needed dependencies...');

        if (self.revisionGuardStore) {
          self.revisionGuard = new RevisionGuard(self.revisionGuardStore, self.options.revisionGuard);
          self.revisionGuard.onEventMissing(function (info, evt) {
            self.onEventMissingHandle(info, evt);
          });
        }

        if (self.options.sagaPath !== '') {
          self.eventDispatcher = new EventDispatcher(self.sagas, self.definitions.event);
          self.sagas.defineOptions({}) // options???
            .defineCommand(self.definitions.command)
            .defineEvent(self.definitions.event)
            .idGenerator(self.getNewId)
            .useSagaStore(self.sagaStore);
        }

        if (self.revisionGuardStore) {
          self.revisionGuard.defineEvent(self.definitions.event);
        }

        callback(null);
      }
    ], function (err) {
      if (err) {
        debug(err);
      }
      if (callback) { callback(err, warnings); }
    });
  }
function ( callback ) { var self = this ; var warnings = null ; async . series ( [ // load saga files... function ( callback ) { if ( self . options . sagaPath === '' ) { self . sagas = { } ; debug ( 'empty sagaPath defined so no sagas will be loaded...' ) ; return callback ( null ) ; } debug ( 'load saga files...' ) ; self . structureLoader ( self . options . sagaPath , function ( err , sagas , warns ) { if ( err ) { return callback ( err ) ; } warnings = warns ; self . sagas = attachLookupFunctions ( sagas ) ; callback ( null ) ; } ) ; } , // prepare infrastructure... function ( callback ) { debug ( 'prepare infrastructure...' ) ; async . parallel ( [ // prepare sagaStore... function ( callback ) { debug ( 'prepare sagaStore...' ) ; self . sagaStore . on ( 'connect' , function ( ) { self . emit ( 'connect' ) ; } ) ; self . sagaStore . on ( 'disconnect' , function ( ) { self . emit ( 'disconnect' ) ; } ) ; self . sagaStore . connect ( callback ) ; } , // prepare revisionGuard... function ( callback ) { debug ( 'prepare revisionGuard...' ) ; if ( ! self . revisionGuardStore ) { return callback ( null ) ; } self . revisionGuardStore . on ( 'connect' , function ( ) { self . emit ( 'connect' ) ; } ) ; self . revisionGuardStore . on ( 'disconnect' , function ( ) { self . emit ( 'disconnect' ) ; } ) ; self . revisionGuardStore . connect ( callback ) ; } ] , callback ) ; } , // inject all needed dependencies... function ( callback ) { debug ( 'inject all needed dependencies...' ) ; if ( self . revisionGuardStore ) { self . revisionGuard = new RevisionGuard ( self . revisionGuardStore , self . options . revisionGuard ) ; self . revisionGuard . onEventMissing ( function ( info , evt ) { self . onEventMissingHandle ( info , evt ) ; } ) ; } if ( self . options . sagaPath !== '' ) { self . eventDispatcher = new EventDispatcher ( self . sagas , self . definitions . event ) ; self . sagas . defineOptions ( { } ) // options??? . defineCommand ( self . definitions . command ) . defineEvent ( self . definitions . event ) . idGenerator ( self . getNewId ) . useSagaStore ( self . sagaStore ) ; } if ( self . revisionGuardStore ) { self . revisionGuard . defineEvent ( self . definitions . event ) ; } callback ( null ) ; } ] , function ( err ) { if ( err ) { debug ( err ) ; } if ( callback ) { callback ( err , warnings ) ; } } ) ; }
Call this function to initialize the saga.
@param {Function} callback the function that will be called when this action has finished [optional]
`function(err){}`
Call this function to initialize the saga .