-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
51 lines (42 loc) · 929 Bytes
/
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
49
50
51
package waitfor
import (
"time"
)
type (
Options struct {
interval time.Duration
maxInterval time.Duration
attempts uint64
}
Option func(opts *Options)
)
// Create new options
func newOptions(setters []Option) *Options {
opts := &Options{
interval: time.Duration(5) * time.Second,
maxInterval: time.Duration(60) * time.Second,
attempts: 5,
}
for _, setter := range setters {
setter(opts)
}
return opts
}
// Set a custom test interval
func WithInterval(interval uint64) Option {
return func(opts *Options) {
opts.interval = time.Duration(interval) * time.Second
}
}
// Set a custom maximum test interval
func WithMaxInterval(interval uint64) Option {
return func(opts *Options) {
opts.maxInterval = time.Duration(interval) * time.Second
}
}
// Set a custom attempts count
func WithAttempts(attempts uint64) Option {
return func(opts *Options) {
opts.attempts = attempts
}
}