acquireSync method
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,
);
}