-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
AsyncLock: public getter for _taken? #34
Comments
No; this would be introducing behavior into the
Adding a There's also a more insidious race condition even with a
As such, most of the time when there's a "skip this if it's already in progress" requirement, the requirement itself is incorrect. It can happen - it's just extremely rare. Usually, some kind of throttling (with at least one "waiting" to get in) is a more reliable solution. I did consider adding both a If you really do need the semantics you describe, then I recommend that you continue doing what your are probably doing now: keeping a separate boolean variable meaning "there's some other code already in this lock and I should skip processing even though there's a small chance that the processing may already be complete so this signal is lost". That way the |
Thanks for your extensive feedback and you are right in everything you said - just haven't thought of everything yet. Especially using some kind of "throtteling" - I just started using Rx someplace else in my application, but I didn't think about using it here until now... |
Would it be possible to add a public getter for
_taken
to theAsyncLock
. I have a usecase where I have an asnyc lock in a method which should not execute a second time if it is already running, so the following would do the trick:In my case the possible race condition for the small gap between the check and the lock beeing taken does not matter as it is only a "performance penalty" if a second call gets to the lock, but maybe you could even implement some kind of
TryLockAsync
which would be thread-safe without a race condition...The text was updated successfully, but these errors were encountered: