Skip to content

Peek, SetLimit, return observed

Choose a tag to compare

@bw19 bw19 released this 22 May 01:58
· 3 commits to main since this release

Allow and AllowN now return (admit bool, observed int) instead of just bool, where observed is the sliding window's load measured before the call — useful for anchoring downstream rejection responses (e.g. a 429) to the actually emitted rate. Two new non-mutating methods, Peek and PeekN, answer the same admit-or-not question without consuming a slot, suitable for filtering candidates or preempting work based on current load. The throttle's limit is now runtime-adjustable via SetLimit and readable via Limit; counters are preserved across changes so the new limit applies against the existing sliding-window history rather than resetting it. Existing call sites must be updated to destructure the new return value (admit, _ := th.Allow()).