Suspending Bucket
SuspendingBucket is an opaque wrapper around Bucket4j's LockFreeBucket, and implements an interface semantically equivalent to BlockingBucket. Whereas Bucket4j's blocking behavior is just that, SuspendingBucket instead delays, making it safe to use in a coroutine context.
Properties
Returns the number of currently available tokens. Delegates directly to the underlying LockFreeBucket's getAvailableTokens implementation.
Returns the Bucket4j BucketConfiguration of the underlying LockFreeBucket. Delegates directly to the underlying LockFreeBucket's getConfiguration implementation.
Functions
Adds the specified number of tokensToAdd to the bucket, not exceeding the capacity of the bucket. Delegates directly to the underlying LockFreeBucket's addTokens implementation.
Consumes the specified number of tokensToConsume, suspending as long as necessary to accumulate the requisite number of tokens. This algorithm is a direct copy of Bucket4j BlockingBucket's consume, except it suspends the calling coroutine's execution while waiting for available tokens, rather than blocking the thread. See the Bucket4j consume documentation for more details.
Adds the specified number of tokensToAdd to the bucket, even if it would result in the bucket containing more than its specified capacity. Delegates directly to the underlying LockFreeBucket's forceAddTokens implementation.
Replaces the bucket's configuration. This delegates directly to the underlying LockFreeBucket's replaceConfiguration implementation.
Tries to consume the specified number of tokensToConsume. Delegates directly to the underlying LockFreeBucket's tryConsume implementation.
Tries to consume the specified number of tokensToConsume, suspending up to maxWaitTime if necessary in order to accumulate enough tokens to consume the specified amount.