acquireSync method

RateLimitGrant acquireSync(
  1. String key,
  2. int maxAttempts,
  3. Duration decay,
  4. int want,
)

Records up to want hits (fewer when the window is nearly full); used by workers to lease a batch of hits in one coordinator round trip.

Implementation

RateLimitGrant acquireSync(
  String key,
  int maxAttempts,
  Duration decay,
  int want,
) {
  final now = _clock().millisecondsSinceEpoch;
  final bucket = _bucket(key, decay, now);
  final free = maxAttempts - bucket.hits;
  final granted = free <= 0 ? 0 : (want < free ? want : free);
  bucket.hits += granted;
  return RateLimitGrant(
    granted: granted,
    hits: bucket.hits,
    resetAtMs: bucket.resetAtMs,
  );
}