-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow acquiring n
permits from PollSemaphore
#5137
Allow acquiring n
permits from PollSemaphore
#5137
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is wrong. You're only handling the case where the permits are immediately available.
Regardless, I'm not sure this should be part of the poll method. Perhaps we should instead provide a method that sets the number of permits to acquire per acquire?
a769f2b
to
9c624c5
Compare
Oops, fixed.
That seems much less ergonomic, especially since the number of permits to acquire may change over time (when using a semaphore to limit requests with different weights or when bounding memory usage). |
You have to reset the future every time you wish to change the number of permits you wish to acquire. Otherwise the method will return a different number of permits than what you're asking for, if the previous permits had a different count. You would need to add a test for this kind of thing. |
286902e
to
d722c37
Compare
83ea7d8
to
59ddfd4
Compare
Adds `PollSemaphore::poll_acquire_many`, to allow acquiring `n` permits from it.
59ddfd4
to
7b655ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Adds
PollSemaphore::poll_acquire_many
, to allow acquiringn
permitsfrom it.
Motivation
Feature parity with
Semaphore
.Solution
Introduce the more general
poll_acquire_many
function, to which thepoll_acquire
one now delegates.