execute method

  1. @override
void execute ([TParam param ])

Calls the wrapped handler function with an option input parameter

Implementation

@override
execute([TParam param])
{


      // print("************ Execute***** canExecute: $_canExecute ***** isExecuting: $_isRunning");

      if (!_canExecute)
      {
        return;
      }

      if (_isRunning)
      {
         return;
      }
      else
      {
        _isRunning = true;
        _canExecuteSubject.add(false);
      }

      _commandResultsSubject.add(new CommandResult<TResult>(_emitLastResult ? lastResult : null,null,true));

      _func(param).asStream()
        .handleError((error)
        {
          if (throwExceptions)
          {
              _resultsSubject.addError(error);
              return;
          }

            if (error is Exception)
            {
              _commandResultsSubject.add(new CommandResult<TResult>(_emitLastResult ? lastResult : null,error,false));
            }
            else
            {
              _commandResultsSubject.add(new CommandResult<TResult>(_emitLastResult ? lastResult : null,new Exception(error.toString()),false));
            }
            _isRunning = false;
            _isExecutingSubject.add(false);
            _canExecuteSubject.add(true);


        })

        .listen( (result) {
            _commandResultsSubject.add(new CommandResult<TResult>(result,null,false));
            lastResult = result;
            _resultsSubject.add(result);
            _isRunning = false;
            _canExecute = !_executionLocked;
            _canExecuteSubject.add(!_executionLocked);
       });
}