lib/pm.js
function (evt, callback) {
    var self = this;

    this.eventDispatcher.dispatch(evt, function (errs, sagaModels) {
      var cmds = [];

      if (!sagaModels || sagaModels.length === 0) {
        if (callback) {
          callback(errs, cmds, []);
        }
        return;
      }

      async.each(sagaModels, function (sagaModel, callback) {

        var cmdsToSend = sagaModel.getUndispatchedCommands();

        function setCommandToDispatched (c, clb) {
          debug('set command to dispatched');
          self.setCommandToDispatched(dotty.get(c, self.definitions.command.id), sagaModel.id, function (err) {
            if (err) {
              return clb(err);
            }
            cmds.push(c);
            sagaModel.removeUnsentCommand(c);
            clb(null);
          });
        }

        async.each(cmdsToSend, function (cmd, callback) {

          if (self.onCommandHandle) {
            debug('publish a command');
            self.onCommandHandle(cmd, function (err) {
              if (err) {
                debug(err);
                return callback(err);
              }
              setCommandToDispatched(cmd, callback);
            });
          } else {
            setCommandToDispatched(cmd, callback);
          }

        }, callback);

      }, function (err) {
        if (err) {
          if (!errs) {
            errs = [err];
          } else if (_.isArray(errs)) {
            errs.unshift(err);
          }
          debug(err);
        }
        if (callback) {
          try {
            callback(errs, cmds, sagaModels);
          } catch (e) {
            debug(e);
            console.log(e.stack);
            process.emit('uncaughtException', e);
          }
        }
      });

    });
  }
function (evt, callback) {
    var self = this;

    this.eventDispatcher.dispatch(evt, function (errs, sagaModels) {
      var cmds = [];

      if (!sagaModels || sagaModels.length === 0) {
        if (callback) {
          callback(errs, cmds, []);
        }
        return;
      }

      async.each(sagaModels, function (sagaModel, callback) {

        var cmdsToSend = sagaModel.getUndispatchedCommands();

        function setCommandToDispatched (c, clb) {
          debug('set command to dispatched');
          self.setCommandToDispatched(dotty.get(c, self.definitions.command.id), sagaModel.id, function (err) {
            if (err) {
              return clb(err);
            }
            cmds.push(c);
            sagaModel.removeUnsentCommand(c);
            clb(null);
          });
        }

        async.each(cmdsToSend, function (cmd, callback) {

          if (self.onCommandHandle) {
            debug('publish a command');
            self.onCommandHandle(cmd, function (err) {
              if (err) {
                debug(err);
                return callback(err);
              }
              setCommandToDispatched(cmd, callback);
            });
          } else {
            setCommandToDispatched(cmd, callback);
          }

        }, callback);

      }, function (err) {
        if (err) {
          if (!errs) {
            errs = [err];
          } else if (_.isArray(errs)) {
            errs.unshift(err);
          }
          debug(err);
        }
        if (callback) {
          try {
            callback(errs, cmds, sagaModels);
          } catch (e) {
            debug(e);
            console.log(e.stack);
            process.emit('uncaughtException', e);
          }
        }
      });

    });
  }
function ( evt , callback ) { var self = this ; this . eventDispatcher . dispatch ( evt , function ( errs , sagaModels ) { var cmds = [ ] ; if ( ! sagaModels || sagaModels . length === 0 ) { if ( callback ) { callback ( errs , cmds , [ ] ) ; } return ; } async . each ( sagaModels , function ( sagaModel , callback ) { var cmdsToSend = sagaModel . getUndispatchedCommands ( ) ; function setCommandToDispatched ( c , clb ) { debug ( 'set command to dispatched' ) ; self . setCommandToDispatched ( dotty . get ( c , self . definitions . command . id ) , sagaModel . id , function ( err ) { if ( err ) { return clb ( err ) ; } cmds . push ( c ) ; sagaModel . removeUnsentCommand ( c ) ; clb ( null ) ; } ) ; } async . each ( cmdsToSend , function ( cmd , callback ) { if ( self . onCommandHandle ) { debug ( 'publish a command' ) ; self . onCommandHandle ( cmd , function ( err ) { if ( err ) { debug ( err ) ; return callback ( err ) ; } setCommandToDispatched ( cmd , callback ) ; } ) ; } else { setCommandToDispatched ( cmd , callback ) ; } } , callback ) ; } , function ( err ) { if ( err ) { if ( ! errs ) { errs = [ err ] ; } else if ( _ . isArray ( errs ) ) { errs . unshift ( err ) ; } debug ( err ) ; } if ( callback ) { try { callback ( errs , cmds , sagaModels ) ; } catch ( e ) { debug ( e ) ; console . log ( e . stack ) ; process . emit ( 'uncaughtException' , e ) ; } } } ) ; } ) ; }
Call this function to forward it to the dispatcher.
@param {Object}   evt      The event object
@param {Function} callback The function that will be called when this action has finished [optional]
`function(errs, evt, notifications){}` notifications is of type Array
Call this function to forward it to the dispatcher .