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

Add Functions to handle Cancellation Token Tasks for ReactiveCommand #3479

Closed

Conversation

ChrisPulman
Copy link
Member

@ChrisPulman ChrisPulman commented Feb 23, 2023

What kind of change does this PR introduce?

Fix for #2716
Fix for #1245
Fix for #2153
Fix for #3450

What is the current behaviour?

ReactiveCommand does not properly support Cancellation tokens properly for CreateFromTask due to an underlying issue in System.Reactive

What is the new behaviour?

Fix the issues with the base functions within RxUI due to and issue with Observable.FromAsync from System.Reactive by using a new Signal.FromTask as the new base, this uses a AnyncSignal base to do the handling exposing the interface IAnyncSignal which inherits from IObservable.

Signal.FromTask 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 with a cancellation token will operate differently
It will have a CancellationTokenSource passed to allow conditional user cancellation instead of a CancellationToken
All overloads will require a return value of Unit or TResult
Cancellation can be done through disposal of the Execute Observable or of the ReactiveCommand to ensure that long running Tasks are not left in limbo.
Ensure that the CancellationToken is passed to all Tasks that are executed in the command execution
Check for CancellationToken.IsCancellationRequested before starting another Task during the overall execution to ensure that you don't use a disposed Token.

Please check if the PR fulfils these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

@codecov
Copy link

codecov bot commented Mar 4, 2023

Codecov Report

Patch coverage: 94.81% and project coverage change: +0.84 🎉

Comparison is base (b49c311) 64.57% compared to head (020553b) 65.41%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3479      +/-   ##
==========================================
+ Coverage   64.57%   65.41%   +0.84%     
==========================================
  Files         156      159       +3     
  Lines        5702     5876     +174     
==========================================
+ Hits         3682     3844     +162     
- Misses       2020     2032      +12     
Impacted Files Coverage Δ
src/ReactiveUI/Signals/AsyncSignal.cs 75.00% <75.00%> (ø)
src/ReactiveUI/Signals/AsyncSignal{T}.cs 86.95% <86.95%> (ø)
src/ReactiveUI/Signals/Signal.cs 95.48% <95.48%> (ø)
src/ReactiveUI/ReactiveCommand/ReactiveCommand.cs 87.89% <100.00%> (+5.06%) ⬆️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ChrisPulman ChrisPulman marked this pull request as ready for review March 6, 2023 02:20
Add missing tests for CreateFromTask<Tin, TOut> overload from last commit
@ChrisPulman ChrisPulman requested a review from RLittlesII March 7, 2023 06:54
@glennawatson glennawatson marked this pull request as draft March 15, 2023 02:00
@glennawatson
Copy link
Contributor

Converting to draft until we decide if we want to introduce the concept of Signal

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2023
@ChrisPulman ChrisPulman deleted the CP_FixReactiveCommand_CreateFromTask_WithToken branch January 24, 2024 21:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants