-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
75 lines (58 loc) · 1.27 KB
/
opts.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package batcher
type options[I any] struct {
maxSize int
workers int
processFn func([]I) error
errorFn func(error)
emitRule EmitRule
}
type Opt[I any] interface {
Apply(*options[I])
}
func Emit[I any](rules ...EmitRule) EmitRuleOpt[I] {
return EmitRuleOpt[I]{
rule: NewMultiEmitRule(rules),
}
}
func Workers[I any](workers int) WorkersOpt[I] {
return WorkersOpt[I]{workers: workers}
}
func MaxSize[I any](maxSize int) MaxSizeOpt[I] {
return MaxSizeOpt[I]{maxSize: maxSize}
}
func Process[I any](fn func([]I) error) ProcessFnOpt[I] {
return ProcessFnOpt[I]{fn: fn}
}
func Error[I any](fn func(error)) ErrProcessFnOpt[I] {
return ErrProcessFnOpt[I]{fn: fn}
}
type WorkersOpt[I any] struct {
workers int
}
func (m WorkersOpt[I]) Apply(o *options[I]) {
o.workers = m.workers
}
type MaxSizeOpt[I any] struct {
maxSize int
}
func (m MaxSizeOpt[I]) Apply(o *options[I]) {
o.maxSize = m.maxSize
}
type ProcessFnOpt[I any] struct {
fn func([]I) error
}
func (m ProcessFnOpt[I]) Apply(o *options[I]) {
o.processFn = m.fn
}
type ErrProcessFnOpt[I any] struct {
fn func(error)
}
func (m ErrProcessFnOpt[I]) Apply(o *options[I]) {
o.errorFn = m.fn
}
type EmitRuleOpt[I any] struct {
rule EmitRule
}
func (m EmitRuleOpt[I]) Apply(o *options[I]) {
o.emitRule = m.rule
}