timeUntilNextToken property

Duration get timeUntilNextToken

Time until next token is available.

Implementation

Duration get timeUntilNextToken {
  _refillTokens();

  if (_tokens >= 1) {
    return Duration.zero;
  }

  final tokensNeeded = 1 - _tokens;
  final intervalsNeeded = tokensNeeded / refillRate;
  final microseconds =
      (intervalsNeeded * refillInterval.inMicroseconds).ceil();

  return Duration(microseconds: microseconds);
}