Skip to content

Little help, Improve MultiLimiter safety and ergonomics#146

Closed
ghost wants to merge 1 commit into
mainfrom
unknown repository
Closed

Little help, Improve MultiLimiter safety and ergonomics#146
ghost wants to merge 1 commit into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Aug 8, 2025

Copy link
Copy Markdown

Safer Options Validation

  • Key must always be non-empty (previously allowed empty when IsUnlimited).
  • Duration must be > 0.

Robust Get Logic

  • Use the ok value from sync.Map.Load instead of checking val == nil.

Useful APIs

  • Exists(key string) bool
  • Keys() []string
  • Delete(keys ...string): Stop + remove to avoid resource retention.
  • CanTakeErr(key string) (bool, error): does not swallow errors.
  • AddAndTakeErr(opts *Options) error: explicit error return.

Ergonomics

  • NewMultiLimiterEmpty(ctx) to create an instance without an initial limiter.
  • GoDoc comments and clarified inline comments.

Enforce non-empty keys for all limiters; require Duration > 0 (safer validation).
Use ok from sync.Map.Load in get (more robust).
Add helpers: Exists, Keys, Delete (Stop + remove), CanTakeErr, AddAndTakeErr.
NewMultiLimiterEmpty(ctx) constructor.
@ghost ghost closed this by deleting the head repository Aug 12, 2025
This pull request was closed.
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.

0 participants