token_bucket_algorithm 0.1.2 copy "token_bucket_algorithm: ^0.1.2" to clipboard
token_bucket_algorithm: ^0.1.2 copied to clipboard

Implementation of the token bucket algorithm for rate limiting e.g. network requests or user actions.

example/main.dart

import 'package:token_bucket_algorithm/token_bucket_algorithm.dart';

void main() {
  final bucket = TokenBucket(
    size: 15,
    refillInterval: const Duration(seconds: 1),
    refillAmount: 10,
    storage: MemoryTokenBucketStorage(),
  );

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

  if (bucket.consume(2)) {
    // Consumed 2 tokens successfully
  }
}
3
likes
160
pub points
9%
popularity

Publisher

verified publishersplashbyte.dev

Implementation of the token bucket algorithm for rate limiting e.g. network requests or user actions.

Repository (GitHub)
View/report issues

Topics

#rate-limit #token-bucket #algorithm #security

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

clock

More

Packages that depend on token_bucket_algorithm