-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
46 lines (37 loc) · 1.03 KB
/
Copy pathoptions.go
File metadata and controls
46 lines (37 loc) · 1.03 KB
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
package chanprobe
// DropPolicy controls what Send and TrySend do when the queue is full.
type DropPolicy int
const (
// Block makes Send wait for space and makes TrySend fail when the queue is full.
Block DropPolicy = iota
// DropNewest rejects the incoming item when the queue is full.
DropNewest
// DropOldest evicts the oldest queued item and inserts the incoming item.
DropOldest
)
// Options configures a Queue.
type Options struct {
DropPolicy DropPolicy
Registry *Registry
}
// Option changes queue construction options.
type Option func(*Options)
// WithDropPolicy sets the queue behavior when it is full.
func WithDropPolicy(policy DropPolicy) Option {
return func(o *Options) {
o.DropPolicy = policy
}
}
// WithRegistry sets the registry used for automatic queue registration.
// Passing nil disables registration.
func WithRegistry(reg *Registry) Option {
return func(o *Options) {
o.Registry = reg
}
}
func defaultOptions() Options {
return Options{
DropPolicy: Block,
Registry: DefaultRegistry(),
}
}