diff --git a/ratelimit.go b/ratelimit.go index 6b37141a..4b692910 100644 --- a/ratelimit.go +++ b/ratelimit.go @@ -210,6 +210,17 @@ func (u *UsageTracker) CheckThresholds() { u.checkThresholdsLocked() } +// DrainAlerts returns all pending alerts and clears the alert buffer. +func (u *UsageTracker) DrainAlerts() []Alert { + u.mu.Lock() + defer u.mu.Unlock() + + alerts := make([]Alert, len(u.Alerts)) + copy(alerts, u.Alerts) + u.Alerts = nil + return alerts +} + func (u *UsageTracker) checkThresholdsLocked() { u.pruneOldLocked()