-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
60 lines (48 loc) · 1.29 KB
/
option.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
// Copyright 2024 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package rego
import "context"
type config struct {
limit uint64
fastFailed bool
newPoolFullErrFunc func(ctx context.Context) error
newPoolClosedErrFunc func(ctx context.Context) error
}
func newDefaultConfig() *config {
conf := &config{
limit: 64,
fastFailed: false,
newPoolFullErrFunc: nil,
newPoolClosedErrFunc: nil,
}
return conf
}
type Option func(conf *config)
func (o Option) ApplyTo(conf *config) {
o(conf)
}
// WithLimit sets limit to config.
func WithLimit(limit uint64) Option {
return func(conf *config) {
conf.limit = limit
}
}
// WithFastFailed sets fastFailed to config.
func WithFastFailed() Option {
return func(conf *config) {
conf.fastFailed = true
}
}
// WithPoolFullErr sets newPoolFullErr to config.
func WithPoolFullErr(newPoolFullErr func(ctx context.Context) error) Option {
return func(conf *config) {
conf.newPoolFullErrFunc = newPoolFullErr
}
}
// WithPoolClosedErr sets newPoolClosedErr to config.
func WithPoolClosedErr(newPoolClosedErr func(ctx context.Context) error) Option {
return func(conf *config) {
conf.newPoolClosedErrFunc = newPoolClosedErr
}
}