Skip to content

Commit

Permalink
Merge pull request #1085 from kentcb/rxcommand-thrownexceptions
Browse files Browse the repository at this point in the history
Ensure exceptions are delivered on output scheduler.
  • Loading branch information
kentcb committed Mar 18, 2016
2 parents 32356c1 + 0bdd971 commit 362de53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
44 changes: 44 additions & 0 deletions ReactiveUI.Tests/ReactiveCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,27 @@ public void ExecuteAsyncTicksAnyLambdaException()
Assert.IsType<InvalidOperationException>(exception);
}

[Fact]
public void ExceptionsAreDeliveredOnOutputScheduler()
{
(new TestScheduler()).With(sched => {
var fixture = ReactiveCommand.CreateFromObservable(() => Observable.Throw<Unit>(new InvalidOperationException()), outputScheduler: sched);
Exception exception = null;
fixture
.ThrownExceptions
.Subscribe(ex => exception = ex);
fixture
.ExecuteAsync()
.Subscribe(
_ => { },
ex => { });
Assert.Null(exception);
sched.Start();
Assert.IsType<InvalidOperationException>(exception);
});
}

[Fact]
public void ExecuteIsAvailableViaICommand()
{
Expand Down Expand Up @@ -635,5 +656,28 @@ public void ExecuteAsyncTicksErrorsInAnyChildCommandThroughThrownExceptions()
Assert.Equal(1, thrownExceptions.Count);
Assert.Equal("oops", thrownExceptions[0].Message);
}

[Fact]
public void ExceptionsAreDeliveredOnOutputScheduler()
{
(new TestScheduler()).With(sched => {
var child = ReactiveCommand.CreateFromObservable(() => Observable.Throw<Unit>(new InvalidOperationException("oops")));
var childCommands = new[] { child };
var fixture = ReactiveCommand.CreateCombined(childCommands, outputScheduler: sched);
Exception exception = null;
fixture
.ThrownExceptions
.Subscribe(ex => exception = ex);
fixture
.ExecuteAsync()
.Subscribe(
_ => { },
ex => { });
Assert.Null(exception);
sched.Start();
Assert.IsType<InvalidOperationException>(exception);
});
}
}
}
4 changes: 2 additions & 2 deletions ReactiveUI/ReactiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ internal protected ReactiveCommand(
.Where(x => x.Demarcation == ExecutionDemarcation.EndWithResult)
.Select(x => x.Result);

this.exceptions = new ScheduledSubject<Exception>(CurrentThreadScheduler.Instance, RxApp.DefaultExceptionHandler);
this.exceptions = new ScheduledSubject<Exception>(outputScheduler, RxApp.DefaultExceptionHandler);

this
.canExecute
Expand Down Expand Up @@ -842,7 +842,7 @@ internal protected CombinedReactiveCommand(
.ThrownExceptions
.Subscribe();

this.exceptions = new ScheduledSubject<Exception>(CurrentThreadScheduler.Instance, RxApp.DefaultExceptionHandler);
this.exceptions = new ScheduledSubject<Exception>(outputScheduler, RxApp.DefaultExceptionHandler);

this
.CanExecute
Expand Down

0 comments on commit 362de53

Please sign in to comment.