| TokenBucket-class | R Documentation |
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.
capacityThe maximum number of tokens in the bucket.
tokensThe number of tokens currently available in the bucket.
intervalThe duration in seconds after which the bucket gets refilled.
last_updateThe timestamp of the last update to the bucket.
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
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.