token_bucket 0.9.7-pre copy "token_bucket: ^0.9.7-pre" to clipboard
token_bucket: ^0.9.7-pre copied to clipboard

Token Bucket is a Dart library for implementing rate limiting using the token bucket algorithm. It provides a simple and efficient way to control the rate of actions in your application.

example/example.dart

import 'package:token_bucket/src/memory_bucket_storage.dart';
import 'package:token_bucket/src/refill_frequency.dart';
import 'package:token_bucket/src/token_bucket.dart';

Future<void> main() async {
  final tokenBucket = TokenBucket(
    capacity: 20,
    frequency: RefillFrequency.second,
    storage: MemoryBucketStorage(),
  );

  await consume(tokenBucket, 10);
  await consume(tokenBucket, 10);
  await consume(tokenBucket, 3);
}

Future<void> consume(TokenBucket bucket, int coast) {
  return bucket.consume(bucketId: 'bucketId', coast: coast).then(print);
}
2
likes
150
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

Token Bucket is a Dart library for implementing rate limiting using the token bucket algorithm. It provides a simple and efficient way to control the rate of actions in your application.

Repository (GitHub)
View/report issues

Topics

#rate-limit #token-bucket

Documentation

API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on token_bucket