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

Feature ReactiveCommand.CreateRunInBackground #3501

Merged
merged 11 commits into from
May 11, 2023

Conversation

ChrisPulman
Copy link
Member

@ChrisPulman ChrisPulman commented Mar 21, 2023

What kind of change does this PR introduce?

Feature for ReactiveCommand

What is the current behaviour?

ReactiveCommand.Create runs Synchronously
ReactiveCommand.CreateFromTask runs Asynchronously
ReactiveCommand.CreateFromObservable runs Asynchronously

What is the new behaviour?

To give the option for all Creation options to operate in the same way a new method CreateRunInBackground has been added to the ReactiveCommand creation options making:
ReactiveCommand.Create runs Synchronously
ReactiveCommand.CreateRunInBackground runs a Method Asynchronously
ReactiveCommand.CreateFromTask runs a Task Asynchronously
ReactiveCommand.CreateFromObservable runs a Observable Asynchronously

What might this PR break?

None expected as existing functionality is default

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 21, 2023

Codecov Report

Patch coverage: 97.69% and project coverage change: +0.30 🎉

Comparison is base (42929d4) 63.60% compared to head (0182a79) 63.91%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3501      +/-   ##
==========================================
+ Coverage   63.60%   63.91%   +0.30%     
==========================================
  Files         157      157              
  Lines        5768     5783      +15     
==========================================
+ Hits         3669     3696      +27     
+ Misses       2099     2087      -12     
Impacted Files Coverage Δ
...eactiveUI/ReactiveCommand/ReactiveCommandMixins.cs 96.96% <88.88%> (+0.04%) ⬆️
src/ReactiveUI/ReactiveCommand/ReactiveCommand.cs 84.11% <99.08%> (+1.28%) ⬆️
...ctiveUI/ReactiveCommand/CombinedReactiveCommand.cs 84.31% <100.00%> (+1.29%) ⬆️
.../ReactiveUI/ReactiveCommand/ReactiveCommandBase.cs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

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

@glennawatson
Copy link
Contributor

Can we change the new flag to be not a optional parameter.

Optional parameter are a breaking API and can break with certain tools, while a method overload is not.

revert version due to extending API instead of changing
@ChrisPulman ChrisPulman changed the title Feature ReactiveCommand.Create RunAsync option Feature ReactiveCommand.CreateAsync Mar 22, 2023
@anaisbetts
Copy link
Member

anaisbetts commented Mar 22, 2023

I have a few questions about this PR, I think we could maybe simplify this implementation quite a bit and make its intent a bit more clear

  • ReactiveCommand.CreateAsync - this is a really ambiguous name, especially in the context of the CreateXXX methods - I think a better name would be something like ReactiveCommand.CreateRunInBackground, where its intended use is more explicit.

Also, I think we can really simplify its implementation, as just a simple proxy to CreateFromObservable, rather than making all of these internal changes:

public static ReactiveUI.ReactiveCommand<TParam, TResult> CreateRunInBackground<TParam, TResult>(
        Func<TParam, TResult> execute, 
        IObservable<bool>? canExecute = null,
        // Rather than "runAsync", always provide a way to control concurrency via an IScheduler
        IScheduler? backgroundScheduler? = null,
        IScheduler? outputScheduler = null) {

    return ReactiveCommand.CreateFromObservable(
        Observable.Start(execute, backgroundScheduler ?? RxApp.TaskPoolScheduler), canExecute, outputScheduler);
}

Thoughts?

@ChrisPulman
Copy link
Member Author

I have a few questions about this PR, I think we could maybe simplify this implementation quite a bit and make its intent a bit more clear

  • ReactiveCommand.CreateAsync - this is a really ambiguous name, especially in the context of the CreateXXX methods - I think a better name would be something like ReactiveCommand.CreateRunInBackground, where its intended use is more explicit.

Also, I think we can really simplify its implementation, as just a simple proxy to CreateFromObservable, rather than making all of these internal changes:

public static ReactiveUI.ReactiveCommand<TParam, TResult> CreateRunInBackground<TParam, TResult>(
        Func<TParam, TResult> execute, 
        IObservable<bool>? canExecute = null,
        // Rather than "runAsync", always provide a way to control concurrency via an IScheduler
        IScheduler? backgroundScheduler? = null,
        IScheduler? outputScheduler = null) {

    return ReactiveCommand.CreateFromObservable(
        Observable.Start(execute, backgroundScheduler ?? RxApp.TaskPoolScheduler), canExecute, outputScheduler);
}

Thoughts?

Thanks Ani, I will update this evening to realign to these thoughts and test to ensure the result is as desired.

@ChrisPulman ChrisPulman marked this pull request as draft March 22, 2023 11:20
@ChrisPulman ChrisPulman changed the title Feature ReactiveCommand.CreateAsync Feature ReactiveCommand.CreateRunInBackground Mar 22, 2023
@ChrisPulman ChrisPulman marked this pull request as ready for review March 22, 2023 19:38
@glennawatson glennawatson merged commit 06459fc into main May 11, 2023
3 checks passed
@glennawatson glennawatson deleted the Feature_OptionalRunAsyncForReactiveCommandCreate branch May 11, 2023 00:25
@github-actions
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 May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants