-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.go
More file actions
51 lines (42 loc) · 930 Bytes
/
option.go
File metadata and controls
51 lines (42 loc) · 930 Bytes
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 queue
import "time"
const (
defaultBatchSize = 10
defaultDelayMin = 10 * time.Millisecond
defaultDelayMax = 3 * time.Second
defaultCommitInterval = time.Second
defaultMaxWait = time.Second
defaultQueueCapacity = 1000
)
type Config struct {
batchSize int
delayMin time.Duration // 消费等待最小延时读
delayMax time.Duration // 消费等待最大延时读
}
func NewConfig(opts ...Option) Config {
ops := Config{
batchSize: defaultBatchSize,
delayMin: defaultDelayMin,
delayMax: defaultDelayMax,
}
for _, opt := range opts {
opt(&ops)
}
return ops
}
type Option func(q *Config)
func WithBatchSize(size int) Option {
return func(opt *Config) {
opt.batchSize = size
}
}
func WithDelayMin(d time.Duration) Option {
return func(q *Config) {
q.delayMin = d
}
}
func WithDelayMax(d time.Duration) Option {
return func(q *Config) {
q.delayMax = d
}
}