Skip to content

Add DiscardAfterThreshold option for SizedGroup - #21

Merged
umputun merged 1 commit into
masterfrom
discard-after-threshold
Nov 17, 2026
Merged

umputun merged 1 commit into
masterfrom
discard-after-threshold

Conversation

@umputun

@umputun umputun commented Nov 17, 2026

Copy link
Copy Markdown
Member

adds DiscardAfterThreshold(n) for SizedGroup, the mode between the default and Discard asked for in #5. The group accepts up to n calls in flight, running or waiting to run, and discards the rest. Go never blocks: accepted calls beyond the group size wait in their goroutines.

it's a second semaphore of size n taken with TryLock in Go and released when the call's goroutine ends, the canceled skip path included. The run limit and the existing modes are untouched.

  • n above the group size overrides Preemptive and Discard passed in any order. Either one left on would block the caller or drop an admitted call holding its slot.
  • n at or below the group size, 0 and negatives included, works as Discard, as Add DiscardWithThreshold support #5 specifies.
  • ErrSizedGroup treats it as Discard.

Fixed #5

DiscardAfterThreshold(n) accepts up to n calls in flight, running or waiting
to run, and discards the rest. Go never blocks: accepted calls beyond the
group size wait in their goroutines. A second semaphore of size n gates
admission, released when the call's goroutine ends, including the canceled
skip path.

With n above the group size the option overrides Preemptive and Discard in
any order, since either left on would block the caller or drop an admitted
call holding its slot. With n at or below the group size, 0 included, it
works as Discard. ErrSizedGroup treats it as Discard.

Fixed #5
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 44025480166

Coverage increased (+0.09%) to 99.015%

Details

  • Coverage increased (+0.09%) from the base build.
  • Patch coverage: 17 of 17 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 203
Covered Lines: 201
Line Coverage: 99.01%
Coverage Strength: 1949.24 hits per line

💛 - Coveralls

@umputun
umputun merged commit 879d203 into master Nov 17, 2026
7 checks passed
@umputun
umputun deleted the discard-after-threshold branch November 17, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DiscardWithThreshold support

2 participants