Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/rx_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CommandError<TParam> {
/// where [TParam] is the type of data that is passed when calling [execute] and
/// [TResult] denotes the return type of the handler function. To signal that
/// a handler doesn't take a parameter or returns no value use the type `void`
abstract class RxCommand<TParam, TResult> extends StreamView<TResult?> {
abstract class RxCommand<TParam, TResult> extends StreamView<TResult> {
bool _isRunning = false;
bool _canExecute = true;
bool _executionLocked = false;
Expand Down Expand Up @@ -533,13 +533,13 @@ abstract class RxCommand<TParam, TResult> extends StreamView<TResult?> {
loggingHandler;

/// This property is a utility which allows us to chain RxCommands together.
Future<TResult?> get next =>
Rx.merge<TResult?>([this, this.thrownExceptions.cast<TResult>()])
Future<TResult> get next =>
Rx.merge<TResult>([this, this.thrownExceptions.cast<TResult>()])
.take(1)
.last;

late Subject<CommandResult<TParam, TResult>> _commandResultsSubject;
final Subject<TResult?> _resultsSubject;
final Subject<TResult> _resultsSubject;
final BehaviorSubject<bool> _isExecutingSubject = BehaviorSubject<bool>();
final BehaviorSubject<bool> _canExecuteSubject = BehaviorSubject<bool>();
final PublishSubject<CommandError<TParam>> _thrownExceptionsSubject =
Expand Down Expand Up @@ -657,7 +657,9 @@ class RxCommandSync<TParam, TResult> extends RxCommand<TParam, TResult> {
result = null;
}
lastResult = result;
_resultsSubject.add(result);
if (result != null || null is TResult) {
_resultsSubject.add(result as TResult);
}
commandResult =
CommandResult<TParam, TResult>(param, result, null, false);
_commandResultsSubject.add(commandResult);
Expand Down
13 changes: 13 additions & 0 deletions test/rx_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,19 @@ void main() {
command2.execute("Non-nullable string");
});


test("Nullability test for next'able", () async {
final cmd = RxCommand.createAsyncNoParam<int>(() async {
await Future.delayed(Duration(milliseconds: 1000));
return 42;
}, initialLastResult: 0);

cmd.execute();
final result = await cmd.next is int;

expect(result, true);
});

// No idea why it's not posible to catch the exception with expect(command.results, emitsError(isException));
/*
test('RxCommand.createFromStreamWithException throw exeption = true', ()
Expand Down