RateLimiter constructor

RateLimiter({
  1. int maxTokens = 10,
  2. int refillRate = 1,
  3. Duration refillInterval = const Duration(seconds: 1),
  4. bool enabled = true,
  5. bool debugMode = false,
  6. String? name,
  7. void onMetrics(
    1. int tokensRemaining,
    2. bool acquired
    )?,
})

Implementation

RateLimiter({
  this.maxTokens = 10,
  this.refillRate = 1,
  this.refillInterval = const Duration(seconds: 1),
  this.enabled = true,
  this.debugMode = false,
  this.name,
  this.onMetrics,
})  : assert(maxTokens > 0, 'maxTokens must be positive'),
      assert(refillRate > 0, 'refillRate must be positive'),
      _tokens = maxTokens.toDouble(),
      _stopwatch = Stopwatch()..start(),
      _lastRefillMicroseconds = 0;