token_bucket_algorithm

Creator: coderz1093

Last updated:

0 purchases

token_bucket_algorithm Image
token_bucket_algorithm Images

Languages

Categories

Add to Cart

Description:

token bucket algorithm

token_bucket_algorithm #






This Dart package provides rate limiting by using an implementation of the token bucket algorithm.
Simple usage #
final bucket = TokenBucket(
size: 15,
refillInterval: const Duration(seconds: 1),
refillAmount: 10,
storage: MemoryTokenBucketStorage(), // optionally change the way the state of the bucket is stored
);

if(bucket.consume()) {
// Consumed 1 token successfully
}

if(bucket.consume(2)) {
// Consumed 2 tokens successfully
}
copied to clipboard
If you want to store the tokens asynchronously in a custom storage, you can also use the AsyncTokenBucket.
final bucket = AsyncTokenBucket(
size: 15,
refillInterval: const Duration(seconds: 1),
refillAmount: 10,
storage: MyCustomAsyncTokenBucketStorage(),
);

if(await bucket.consume()) {
// Consumed 1 token successfully
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.