Struct: ratelimit.TokenBucket
Overview
TokenBucket provides a concurrency safe utility for adding and removing tokens from the available token bucket.
Implemented Interfaces
types.AnalyticsFilter, aws.CredentialsProvider, v4.HTTPPresigner, s3.HTTPPresignerV4, types.MetricsFilter, s3.PresignPost, customizations.S3ExpressCredentialsProvider, arn.S3ObjectLambdaARN, types.SelectObjectContentEventStream
Constructor Functions collapse
-
func NewTokenBucket(i uint) *TokenBucket
NewTokenBucket returns an initialized TokenBucket with the capacity specified.
Method Summary collapse
-
func (t *TokenBucket) Capacity() uint
Capacity returns the maximum capacity of tokens that the bucket could contain.
-
func (t *TokenBucket) Refund(amount uint)
Refund returns the amount of tokens back to the available token bucket, up to the initial capacity.
-
func (t *TokenBucket) Remaining() uint
Remaining returns the number of tokens that remaining in the bucket.
-
func (t *TokenBucket) Resize(size uint) uint
Resize adjusts the size of the token bucket.
-
func (t *TokenBucket) Retrieve(amount uint) (available uint, retrieved bool)
Retrieve attempts to reduce the available tokens by the amount requested.
Function Details
func NewTokenBucket(i uint) *TokenBucket
NewTokenBucket returns an initialized TokenBucket with the capacity specified.
17 18 19 20 21 22 23 |
// File 'aws/ratelimit/token_bucket.go', line 17
|
Method Details
func (t *TokenBucket) Capacity() uint
Capacity returns the maximum capacity of tokens that the bucket could contain.
55 56 57 58 59 60 |
// File 'aws/ratelimit/token_bucket.go', line 55
|
func (t *TokenBucket) Refund(amount uint)
Refund returns the amount of tokens back to the available token bucket, up to the initial capacity.
45 46 47 48 49 50 51 |
// File 'aws/ratelimit/token_bucket.go', line 45
|
func (t *TokenBucket) Remaining() uint
Remaining returns the number of tokens that remaining in the bucket.
63 64 65 66 67 68 |
// File 'aws/ratelimit/token_bucket.go', line 63
|
func (t *TokenBucket) Resize(size uint) uint
Resize adjusts the size of the token bucket. Returns the capacity remaining.
71 72 73 74 75 76 77 78 79 80 81 |
// File 'aws/ratelimit/token_bucket.go', line 71
|
func (t *TokenBucket) Retrieve(amount uint) (available uint, retrieved bool)
Retrieve attempts to reduce the available tokens by the amount requested. If there are tokens available true will be returned along with the number of available tokens remaining. If amount requested is larger than the available capacity, false will be returned along with the available capacity. If the amount is less than the available capacity, the capacity will be reduced by that amount, and the remaining capacity and true will be returned.
31 32 33 34 35 36 37 38 39 40 41 |
// File 'aws/ratelimit/token_bucket.go', line 31
|