execute method
- @override
Calls the wrapped handler function with an option input parameter
Implementation
@override
execute([TParam param])
{
if (!_canExecute)
{
return;
}
if (_isRunning)
{
return;
}
else
{
_isRunning = true;
_canExecuteSubject.add(false);
}
_isExecutingSubject.add(true);
_commandResultsSubject.add(new CommandResult<TResult>(null,null,true));
Exception thrownException;
var inputObservable = new Observable(_observableProvider(param))
.handleError((error)
{
if (error is Exception)
{
thrownException = error;
}
else
{
thrownException= new Exception(error.toString());
}
})
.doOnData( (result) => _resultsSubject.add(result))
.map( (result) => new CommandResult(result, null, false));
_commandResultsSubject.addStream(inputObservable)
.then((_) {
if (thrownException != null)
{
if (throwExceptions)
{
_resultsSubject.addError(thrownException);
_commandResultsSubject.addError(thrownException);
}
else
{
_thrownExceptionsSubject.add(thrownException);
_commandResultsSubject.add(new CommandResult<TResult>(null,thrownException,false));
}
}
_isRunning = false;
_canExecuteSubject.add(true);
}, onError: (error) {
print(error);
});
}