-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
55 lines (47 loc) · 1.61 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
49
50
51
52
53
54
55
package ariadne
import (
"time"
)
// FetchBlocksOption is used to tune FetchBlocks method.
type FetchBlocksOption func(f *FetchBlocksOptions)
// FetchBlocksOptions is config for FetchBlocks method.
type FetchBlocksOptions struct {
// How long should fetcher wait if fetcher got ErrTooHighBlockRequested.
retryLastBlockInterval time.Duration
// How long should fetcher wait after error.
retryInterval time.Duration
// errHandler will be called when fetcher will get an error.
errHandler func(height uint64, err error)
// skipError disable retries of block handling with handleFunc.
skipError bool
}
var defaultFetchBlockOptions = FetchBlocksOptions{
retryLastBlockInterval: time.Second,
retryInterval: time.Second,
errHandler: func(height uint64, err error) {},
skipError: false,
}
// WithRetryLastBlockInterval sets how long should fetcher wait if fetcher got ErrTooHighBlockRequested.
func WithRetryLastBlockInterval(d time.Duration) FetchBlocksOption {
return func(opts *FetchBlocksOptions) {
opts.retryLastBlockInterval = d
}
}
// WithRetryInterval sets pause duration after error.
func WithRetryInterval(d time.Duration) FetchBlocksOption {
return func(opts *FetchBlocksOptions) {
opts.retryInterval = d
}
}
// WithErrHandler sets function to process errors.
func WithErrHandler(f func(height uint64, err error)) FetchBlocksOption {
return func(opts *FetchBlocksOptions) {
opts.errHandler = f
}
}
// WithSkipError disable retries of block handling with handleFunc.
func WithSkipError(b bool) FetchBlocksOption {
return func(f *FetchBlocksOptions) {
f.skipError = b
}
}