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

Cancellable commands #581

Closed
VTJDailey opened this issue May 6, 2014 · 1 comment
Closed

Cancellable commands #581

VTJDailey opened this issue May 6, 2014 · 1 comment
Labels

Comments

@VTJDailey
Copy link

Has there been any discussion in the past on integrating CancellationToken support in ReactiveCommand?

Looking at the rxui 6 codebase I'm imagining the constructor parameter changing to:

    Func<object, CancellationToken, IObservable<T>> executeAsync

The intent would be that the async implementation would return an empty observable if it wanted to respect a cancel operation.

ExecuteAsync could take a CancellationToken parameter with a default of CancellationToken.None.

The downside would seem to be that this would require every use of this class to include CancellationToken in the async function signature, whether it's used or not. That could be mitigated by adding more of the static method 'constructors' but there's already a ton of them. On the other hand the static methods could keep the current parameters, wrap it to pass to the real class, and anyone wanting to use cancellation support just has to use the real class constructor.

I'd be willing to take a stab at implementing this as long as it's something that you'd have genuine interest in pulling in.

@anaisbetts
Copy link
Member

This actually isn't how Cancellation works in Rx - the way that you implement cancellation is via the implementation of your IObservable; when someone Unsubscribes, you stop doing work. Usually, the easiest way to get this done is via Observable.Create, because it lets you return a Disposable which is disposed on Unsubscribe.

There are also several methods in Rx that "marshal" between TPL Cancellation Zen Nature™ and Rx Cancellation Zen Nature™ - any Rx method that provides CancellationTokens will cancel that token when someone unsubscribes, grep through the source for the symbol NO_TPL to find them. A few off the top of my head are:

  • Create
  • SelectMany
  • StartAsync
  • DeferAsync
  • Task.ToObservable
  • Using

@lock lock bot added the outdated label Jun 26, 2019
@lock lock bot locked and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants