1package retry
2
3import (
4 "context"
5 "time"
6)
7
8// Constant is a wrapper around Retry that uses a constant backoff. It panics if
9// the given base is less than zero.
10func Constant(ctx context.Context, t time.Duration, f RetryFunc) error {
11 return Do(ctx, NewConstant(t), f)
12}
13
14// NewConstant creates a new constant backoff using the value t. The wait time
15// is the provided constant value. It panics if the given base is less than
16// zero.
17func NewConstant(t time.Duration) Backoff {
18 if t <= 0 {
19 panic("t must be greater than 0")
20 }
21
22 return BackoffFunc(func() (time.Duration, bool) {
23 return t, false
24 })
25}