getTimeUntilRateLimitLifted method
Gets the time until rate limiting is lifted (if currently rate limited).
Returns null if not rate limited, or the duration until rate limit
is lifted if rate limited.
Implementation
Duration? getTimeUntilRateLimitLifted({
int maxAttempts = 5,
Duration timeWindow = const Duration(minutes: 15),
}) {
if (!shouldRateLimit(maxAttempts: maxAttempts, timeWindow: timeWindow)) {
return null;
}
if (_lastFailedAttempt == null) {
return null;
}
final now = DateTime.now();
final timeSinceLastAttempt = now.difference(_lastFailedAttempt!);
final remaining = timeWindow - timeSinceLastAttempt;
return remaining.isNegative ? null : remaining;
}