-
Notifications
You must be signed in to change notification settings - Fork 753
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 request] Implement ToObservable for CancellationToken #1773
Comments
Also good to see I'm not alone who finds this feature useful: https://stackoverflow.com/a/65202543/1768303 |
I do see how this can be useful. I don't have a clear opinion yet (nor am I who can make a decision) nonetheless I want to share my thoughts. The semantics of cancellation of TPL and Rx are quite different. In Rx, you cancel a subscription, that is, you request to stop consumption of new notifications. On the other hand in TPL, a cancellation is a request to stop the production. Due to its imperative nature, this works with exception. The consumer has to actively consider the canceled outcome. Having this in mind, I'm not sure how an Maybe it is more fertile to look on the actual use cases. I think in your cases the |
Hi @quinmars, thanks for replying!
FWIW, if I complete the |
Just need to include an OnNext right before the OnCompleted (TakeUntil looks for an emission rather than completion). |
I've update the code to offer a choice between |
My $0.02: I am using the I am surprised that this isn't already a feature. It works great with awaiting an observable. If the common TPL pattern is that every awaitable has an optional cancel token, it seems like an oversight that you can await an observable but not cancel it. |
Feature request
A function to convert a
CancellationToken
token into an observable that emitOnError
withOperationCanceledException
when the token is signaled. It can possibly be implemented like this:Patch or Minor
All supported platforms
Company-wide
Here's one possible use case, coupled with
TakeUntil
(I'm sure there are many others). Here, theFinally
action is called upon the first item emit or when the token is signaled.This code here is a bit contrived (I might as well use
IObservable<T>.ToTask
orIObservable<T>.RunAsync
) but in our real-life Rx piple-lines this use case does makes sense:Updated, the initial version was rather naive, a race condition has emerged since I stated using it. Here is an updated version aiming to solve it, and also giving a choice whether to use
OnError
orOnNext
:The text was updated successfully, but these errors were encountered: