-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
48 lines (40 loc) · 1.16 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package again
import "time"
// Option is a function type that can be used to configure the `Retrier` struct.
type Option func(*Retrier)
// applyOptions applies the options to the retrier.
func applyOptions(retrier *Retrier, options ...Option) {
for _, option := range options {
option(retrier)
}
}
// WithMaxRetries returns an option that sets the maximum number of retries.
func WithMaxRetries(num int) Option {
return func(retrier *Retrier) {
retrier.MaxRetries = num
}
}
// WithJitter returns an option that sets the jitter.
func WithJitter(jitter time.Duration) Option {
return func(retrier *Retrier) {
retrier.Jitter = jitter
}
}
// WithBackoffFactor returns an option that sets the backoff factor.
func WithBackoffFactor(factor float64) Option {
return func(retrier *Retrier) {
retrier.BackoffFactor = factor
}
}
// WithInterval returns an option that sets the interval.
func WithInterval(interval time.Duration) Option {
return func(retrier *Retrier) {
retrier.Interval = interval
}
}
// WithTimeout returns an option that sets the timeout.
func WithTimeout(timeout time.Duration) Option {
return func(retrier *Retrier) {
retrier.Timeout = timeout
}
}