TokenBucket-class: TokenBucket Class

TokenBucket-classR Documentation

TokenBucket Class

Description

This class represents a token bucket, which is a rate limiting mechanism used to control the frequency of certain actions or requests based on available tokens. Tokens are added to the bucket at a specified rate and can be consumed when needed.

Fields

capacity

The maximum number of tokens in the bucket.

tokens

The number of tokens currently available in the bucket.

interval

The duration in seconds after which the bucket gets refilled.

last_update

The timestamp of the last update to the bucket.

Examples


try({
# create token bucket
bucket <- TokenBucket(
  capacity = 10,
  tokens = 10,
  intervall = 1,
  last_update = Sys.Time()
)

# add tokens to bucket
bucket$addTokens()

# check if a token is available
bucket$isTokenAvailable

# consume token
bucket$consumeToken
})


impectR documentation built on Dec. 17, 2025, 5:09 p.m.