Struct: ratelimit.TokenRateLimit

import "../ibm-cos-sdk-go-v2/aws/ratelimit"

Overview

TokenRateLimit provides a Token Bucket RateLimiter implementation that limits the overall number of retry attempts that can be made across operation invocations.

Implemented Interfaces

types.AnalyticsFilter, v4.HTTPPresigner, s3.HTTPPresignerV4, types.MetricsFilter, s3.PresignPost, retry.RateLimiter, arn.S3ObjectLambdaARN, types.SelectObjectContentEventStream

Constructor Functions collapse

Method Summary collapse

Function Details

func NewTokenRateLimit(tokens uint) *TokenRateLimit

NewTokenRateLimit returns an TokenRateLimit with default values. Functional options can configure the retry rate limiter.



26
27
28
29
30
// File 'aws/ratelimit/token_rate_limit.go', line 26

func NewTokenRateLimit(tokens uint) *TokenRateLimit { return &TokenRateLimit{ bucket: NewTokenBucket(tokens), } }

Method Details

func (l *TokenRateLimit) AddTokens(v uint) error

AddTokens increments the token bucket by a fixed amount.



62
63
64
65
// File 'aws/ratelimit/token_rate_limit.go', line 62

func (l *TokenRateLimit) AddTokens(v uint) error { l.bucket.Refund(v) return nil }

func (l *TokenRateLimit) GetToken(ctx context.Context, cost uint) (func() error, error)

GetToken may cause a available pool of retry quota to be decremented. Will return an error if the decremented value can not be reduced from the retry quota.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// File 'aws/ratelimit/token_rate_limit.go', line 45

func (l *TokenRateLimit) GetToken(ctx context.Context, cost uint) (func() error, error) { select { case <-ctx.Done(): return nil, canceledError{Err: ctx.Err()} default: } if avail, ok := l.bucket.Retrieve(cost); !ok { return nil, QuotaExceededError{Available: avail, Requested: cost} } return rateToken{ tokenCost: cost, bucket: l.bucket, }.release, nil }

func (l *TokenRateLimit) Remaining() uint

Remaining returns the number of remaining tokens in the bucket.



68
69
70
// File 'aws/ratelimit/token_rate_limit.go', line 68

func (l *TokenRateLimit) Remaining() uint { return l.bucket.Remaining() }