A Go library for series of time intervals: schedules that resolve in
time.Duration, ready for time.Sleep, retry loops, and schedulers.
Each series type shares the same duration-first shape: given a reference
time.Time, it tells you how long until the next occurrence (and, where it
makes sense, how long since the previous one). The calendar or backoff math
stays internal; the public contract is a duration.
cron— parses standard cron expressions and resolves the next/previous occurrence, in both absolute time and duration form.backoff— pluggable exponential backoff strategies, with optional jitter, for retry policies.
bi := backoff.NewFullJitterBackoffInterval(500 * time.Millisecond)
for {
if err := doSomething(); err != nil {
time.Sleep(bi.Next())
continue
}
break
}BackoffInterval is a generic retry-delay engine: pluggable nextFunc/
resetFunc pairs drive the sequence, so new strategies plug in without new
concrete types. Jitter strategies follow the AWS Architecture Blog reference
"Exponential Backoff and Jitter":
| Strategy | Formula | Constructor |
|---|---|---|
FullJitter (default) |
random(0, interval) |
NewFullJitterBackoffInterval |
EqualJitter |
interval/2 + random(0, interval/2) |
NewEqualJitterBackoffInterval |
DecorrelatedJitter |
min(cap, random(base, prevSleep*3)) |
NewDecorrelatedBackoffInterval |
PercentJitter |
interval ± Randomizer% (this package's own; not from the AWS reference) |
NewPercentJitterBackoffInterval |
DecorrelatedJitter is structurally different from the other three: its
recurrence depends on the previously returned sleep instead of a
deterministic exponential ramp, so it runs as its own engine rather than a
jitter strategy plugged into the exponential one.
WrapError attaches the current backoff interval to an error, without
losing the original via errors.Is/errors.As:
if err != nil {
return bi.WrapError(err)
}IntervalOK is one of the Candango Open Source Group initiatives.
For bug reports, feature requests, and questions, please open an issue on GitHub.
NvimIM is distributed under the MIT License. See the LICENSE file for details.