Skip to content

bucket.asBlocking().tryConsume(t, Duration.ofSeconds(20)) sometimes does not wait #427

Discussion options

You must be logged in to vote

@PeterTeunissen hello,

I was assuming the bucket.asBlocking().tryConsume(t, Duration.ofSeconds(20)) method would wait at least 20 seconds to see if a token becomes available (either from some process calling addToken, or a refillInterval happening).

As mentioneed in javadocs asBlocking().tryConsume() operates only with refill time requires to close deficit. If it is known that specified waitThreshold is not enough to refill requested amount of tokens then it returns false imediatelly. Expectation that asBlocking().tryConsume interracts with addToken and wise versa, is not true.

Also it needs to understand that if thread is became blocked, then it is guaranteed that this thread will cons…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@PeterTeunissen
Comment options

@vladimir-bukhtoyarov
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