-
Notifications
You must be signed in to change notification settings - Fork 747
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: Make AsyncGate.LockAsync
cancellable
#2148
Comments
It's not AsyncRx.NET's goal to provide general-purpose asynchronous utilities, so I would only want to add features to In fact, my first thought here is: should This is not an area of AsyncRx.Net that I've explored yet. (We inherited this code when we took over maintenance of Rx, and most of our focus so far has been elsewhere.) So I need to attempt to understand the thinking behind the fact that As far as I can tell, it currently appears in just two public APIs: public static class Observable
{
public static IObservable<TSource> Synchronize<TSource>(this IObservable<TSource> source, object gate)
}
public static class Observer
{
public static IObserver<T> Synchronize<T>(IObserver<T> observer, object gate)
} Note that these take a plain So these Rx.NET methods offer two capabilities:
AsyncRx.NET faces a challenge in implementing the same service: the synchronization capability available for any object (i.e. what we use through So to enable the two capabilities described above we can't use What we would want to do is use the async equivalent of dotnet/runtime#34812 (comment) (The basic issue is that thread affinity is part of the design, which rules out async.) There is a very long-standing request to add an So the original AsyncRx.NET implementors' decision to define their own That shuts down my initial thought: no, this type should not be So, given that we need to provide However... There's one notable feature of the discussion linked to above in the proposal for adding I'm wondering if we should in fact take a completely different approach. I'm wondering if we should define an (AsyncRx.NET is still in preview, so we can make breaking changes like this.) In fact I'd be inclined to make all of So AsyncRx.NET would make no attempt to support cancellation, but it would become possible for application code to supply its own This approach would remove the block that prevents you from doing what you want. It's not quite what you asked for, because we wouldn't be providing the solution we want, but we would a) make it possible for you to write such a solution, and b) leave the door open for using a future .NET-supplied async lock primitive if they ever add such a thing. Also, if you're already using a library that provide such a primitive (and I gather project Orleans does) you could use that. I prefer that to an API design that forces you to use our type. So this would provide a way for you to do what you want. How does that sound? |
@idg10 thanks for the thorough response, using an interface sounds like an appropriate fix for Rx. It's easy enough for me to copy over I'll admit I'm using some (useful) exposed public classes outside of the scope of Rx. For example, I'm guessing I shouldn't rely on the implementation of |
I apologise for not noticing that Q&A early. I thought GitHub would notify me when people posted in there, but I guess not! You can totally rely on all our public |
I've prototyped an implementation of this I'll post again here once a usable preview is available. |
(I am still trying to solve the code signing! I was off sick for a bit, and then on vacation for a while, and I now think it's possible that the person at the .NET Foundation whose help I need to get code signing reinstated may be on vacation... But I haven't forgotten this.) |
The underlying
SemaphoreSlim.WaitAsync
already supports cancellation. Can a parameter be exposed to pass a token down to this line?reactive/AsyncRx.NET/System.Reactive.Async/Threading/AsyncGate.cs
Line 35 in 5f831de
The text was updated successfully, but these errors were encountered: