Skip to content

Is there any way to subscribe to the event of bucket refill? #224

Answered by DAv10195
DAv10195 asked this question in Q&A
Discussion options

You must be logged in to vote

Looks like I found a way to avoid the busy waiting with the sleep time. When bucket.tryConsume(1) returns false, I run the following code:

bucket.asBlocking().consume(1); bucket.addTokens(1);

Which leads to the consumer thread being blocked until the bucket get refilled. When it wakes up, it immediately returns the consumed token to the bucket.

What do you think about this solution? is it a recommended way to achieve this behavior?

Thanks again,
David

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@vladimir-bukhtoyarov
Comment options

@DAv10195
Comment options

Answer selected by vladimir-bukhtoyarov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants