Skip to content

Commit fb800f0

Browse files
authored
Fix to handle Cancellation Token Tasks for ReactiveCommand.CreateFromTask (#3704)
<!-- Please be sure to read the [Contribute](https://github.com/reactiveui/reactiveui#contribute) section of the README --> **What kind of change does this PR introduce?** <!-- Bug fix, feature, docs update, ... --> Fix for #1245 Fix for #2153 Fix for #3450 **What is the current behavior?** <!-- You can also link to an open issue here. --> ReactiveCommand does not properly support Cancellation tokens properly for CreateFromTask due to an underlying issue in System.Reactive **What is the new behavior?** <!-- If this is a feature change --> Fix the issues with the base functions within ReactiveCommand due to an issue with Observable.FromAsync from System.Reactive by using a new ObservableMixins.FromAsyncWithAllNotifications as the new function, this extends Observable.FromAsync handling the error bubbling as required. ObservableMixins.FromAsyncWithAllNotifications can be used to transform a Cancellation Task into an Observable producing the expected cancellation, errors and results. **What might this PR break?** ReactiveCommand.CreateFromTask will now handle exceptions as expected, any existing workarounds could be removed once tested with actual implementation in end users code. **Please check if the PR fulfills these requirements** - [x] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been added / updated (for bug fixes / features) **Other information**: Co-authored-by: @idg10 - created the base code in #3556
1 parent 2d7801e commit fb800f0

9 files changed

+603
-103
lines changed

src/ReactiveUI.Fody.Analyzer.Test/ReactiveUI.Fody.Analyzer.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>net472;net6.0</TargetFrameworks>
44
<IsPackable>false</IsPackable>
5+
<NoWarn>$(NoWarn);MSB3243</NoWarn>
56
</PropertyGroup>
67
<ItemGroup>
78
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.DotNet6_0.verified.txt

+3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ namespace ReactiveUI
695695
}
696696
public class ReactiveCommand<TParam, TResult> : ReactiveUI.ReactiveCommandBase<TParam, TResult>
697697
{
698+
protected ReactiveCommand([System.Runtime.CompilerServices.TupleElementNames(new string?[]?[] {
699+
"Result",
700+
"Cancel"})] System.Func<TParam, System.IObservable<System.ValueTuple<System.IObservable<TResult>, System.Action>>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
698701
protected ReactiveCommand(System.Func<TParam, System.IObservable<TResult>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
699702
public override System.IObservable<bool> CanExecute { get; }
700703
public override System.IObservable<bool> IsExecuting { get; }

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.DotNet7_0.verified.txt

+3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ namespace ReactiveUI
695695
}
696696
public class ReactiveCommand<TParam, TResult> : ReactiveUI.ReactiveCommandBase<TParam, TResult>
697697
{
698+
protected ReactiveCommand([System.Runtime.CompilerServices.TupleElementNames(new string?[]?[] {
699+
"Result",
700+
"Cancel"})] System.Func<TParam, System.IObservable<System.ValueTuple<System.IObservable<TResult>, System.Action>>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
698701
protected ReactiveCommand(System.Func<TParam, System.IObservable<TResult>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
699702
public override System.IObservable<bool> CanExecute { get; }
700703
public override System.IObservable<bool> IsExecuting { get; }

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.DotNet8_0.verified.txt

+3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ namespace ReactiveUI
695695
}
696696
public class ReactiveCommand<TParam, TResult> : ReactiveUI.ReactiveCommandBase<TParam, TResult>
697697
{
698+
protected ReactiveCommand([System.Runtime.CompilerServices.TupleElementNames(new string?[]?[] {
699+
"Result",
700+
"Cancel"})] System.Func<TParam, System.IObservable<System.ValueTuple<System.IObservable<TResult>, System.Action>>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
698701
protected ReactiveCommand(System.Func<TParam, System.IObservable<TResult>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
699702
public override System.IObservable<bool> CanExecute { get; }
700703
public override System.IObservable<bool> IsExecuting { get; }

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.Net4_7.verified.txt

+3
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,9 @@ namespace ReactiveUI
693693
}
694694
public class ReactiveCommand<TParam, TResult> : ReactiveUI.ReactiveCommandBase<TParam, TResult>
695695
{
696+
protected ReactiveCommand([System.Runtime.CompilerServices.TupleElementNames(new string?[]?[] {
697+
"Result",
698+
"Cancel"})] System.Func<TParam, System.IObservable<System.ValueTuple<System.IObservable<TResult>, System.Action>>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
696699
protected ReactiveCommand(System.Func<TParam, System.IObservable<TResult>> execute, System.IObservable<bool>? canExecute, System.Reactive.Concurrency.IScheduler? outputScheduler) { }
697700
public override System.IObservable<bool> CanExecute { get; }
698701
public override System.IObservable<bool> IsExecuting { get; }

0 commit comments

Comments
 (0)