Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure exceptions are delivered on output scheduler. #1085

Merged
merged 1 commit into from Mar 18, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions ReactiveUI.Tests/ReactiveCommandTest.cs
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
Expand Up @@ -647,7 +647,7 @@ public class ReactiveCommand<TParam, TResult> : ReactiveCommandBase<TParam, TRes
.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 @@ public class CombinedReactiveCommand<TParam, TResult> : ReactiveCommandBase<TPar
.ThrownExceptions
.Subscribe();

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

this
.CanExecute
Expand Down