Documentation
¶
Overview ¶
Package jitter adds randomized jitter to backoff and retry durations to avoid a thundering herd. It guards against non-positive inputs so callers can pass values like time.Until(resetTime) directly — a rate-limit reset that has already elapsed yields a negative duration, which must not panic.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add adds 0% to +100% random jitter to avoid thundering herd. A non-positive duration is returned unchanged, so callers that pass the result to workqueue.RequeueAfter stay safe when a rate-limit reset time has already elapsed and time.Until returns a negative duration.
Example ¶
package main
import (
"fmt"
"time"
"chainguard.dev/driftlessaf/internal/jitter"
)
func main() {
// A non-positive duration is returned unchanged.
fmt.Println(jitter.Add(0))
fmt.Println(jitter.Add(-time.Second) == -time.Second)
// A positive duration is returned with 0–100% jitter added.
result := jitter.Add(time.Second)
fmt.Println(result >= time.Second && result <= 2*time.Second)
}
Output: 0s true true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.