-
Notifications
You must be signed in to change notification settings - Fork 52
/
options.go
57 lines (45 loc) · 1.44 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
56
57
package task
import (
"github.com/dobyte/due/v2/etc"
)
const (
defaultSize = 100000 // 默认任务池大小
defaultNonblocking = true // 默认是否非阻塞
defaultDisablePurge = true // 默认是否禁用清除
)
const (
defaultSizeKey = "etc.taskPool.size" // 任务池大小
defaultNonblockingKey = "etc.taskPool.nonblocking" // 是否非阻塞
defaultDisablePurgeKey = "etc.taskPool.disablePurge" // 是否禁用清除
)
type options struct {
size int // 任务池大小
nonblocking bool // 是否非阻塞
disablePurge bool // 是否禁用清除
}
type Option func(o *options)
func defaultOptions() *options {
opts := &options{
size: defaultSize,
nonblocking: defaultNonblocking,
disablePurge: defaultDisablePurge,
}
if size := etc.Get(defaultSizeKey).Int(); size > 0 {
opts.size = size
}
opts.nonblocking = etc.Get(defaultNonblockingKey, defaultNonblocking).Bool()
opts.disablePurge = etc.Get(defaultDisablePurgeKey, defaultDisablePurge).Bool()
return opts
}
// WithSize 设置任务池大小
func WithSize(size int) Option {
return func(o *options) { o.size = size }
}
// WithNonblocking 设置是否非阻塞
func WithNonblocking(nonblocking bool) Option {
return func(o *options) { o.nonblocking = nonblocking }
}
// WithDisablePurge 设置是否禁用清除
func WithDisablePurge(disablePurge bool) Option {
return func(o *options) { o.disablePurge = disablePurge }
}