-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
41 lines (34 loc) · 1002 Bytes
/
config.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
package haro
import "time"
type subscriberConfig struct {
retry int
retryDelay time.Duration
onError func(error)
onSuccess func()
}
// SubscriberConfigFunc is signature of function for doing configuration
type SubscriberConfigFunc func(*subscriberConfig)
// Retry configures how many times should the subscriber retries before really failing
func Retry(count int) SubscriberConfigFunc {
return func(cfg *subscriberConfig) {
cfg.retry = count
}
}
// DelayRetry configures delay between each retry
func DelayRetry(delay time.Duration) SubscriberConfigFunc {
return func(cfg *subscriberConfig) {
cfg.retryDelay = delay
}
}
// OnError specify what to do when error occured
func OnError(onError func(error)) SubscriberConfigFunc {
return func(cfg *subscriberConfig) {
cfg.onError = onError
}
}
// OnSuccess specify what to do when no error occured
func OnSuccess(onSuccess func()) SubscriberConfigFunc {
return func(cfg *subscriberConfig) {
cfg.onSuccess = onSuccess
}
}