Skip to content

feat: make AdaptiveThrottle instances independently configurable#7

Merged
basgys merged 1 commit intomainfrom
feat/instance-config
Mar 15, 2026
Merged

feat: make AdaptiveThrottle instances independently configurable#7
basgys merged 1 commit intomainfrom
feat/instance-config

Conversation

@basgys
Copy link
Copy Markdown
Contributor

@basgys basgys commented Mar 15, 2026

Summary

The global variables IsRejectedError, ClientSideRejectionError, and
Now made it impossible to run multiple AdaptiveThrottle instances
with different behaviour, and caused tests to share clock and error
classification state.

This PR introduces per-instance equivalents via three new options:

New option Replaces global
WithRejectedErrorFunc(fn) IsRejectedError
WithClientSideRejectionError(err) ClientSideRejectionError
WithNow(fn) Now

Each option falls back to the corresponding global when not set, so all
existing code continues to work without changes.

The globals are marked deprecated with a pointer to their per-instance
replacement. They will be removed in v2.

Backward compatibility

No breaking changes. Callers that mutate the globals directly continue
to work as before; the fallback path reads the global at call time.

Add three new AdaptiveThrottleOption constructors that let each instance override the behaviour previously only configurable via globals:

  WithRejectedErrorFunc    — replaces global IsRejectedError
  WithClientSideRejectionError — replaces global ClientSideRejectionError
  WithNow                  — replaces global Now

Each falls back to the corresponding global when not set, preserving
full backward compatibility. The globals are now deprecated in favour of
the per-instance options.

The constructor also uses WithNow when seeding the initial windowed
counters, so clock control is complete from the moment of construction.
@basgys basgys merged commit 87c7482 into main Mar 15, 2026
2 checks passed
@basgys basgys deleted the feat/instance-config branch March 15, 2026 14:59
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.

1 participant