-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
48 lines (36 loc) · 1 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
package bpool
import (
"time"
)
// Options holds the optional BufferPool parameters.
type Options struct {
// Maximum concurrent buffer can get from pool
MaxPoolSize int
// The duration for waiting in the queue if buffer pool reaches its target size
InitialInterval time.Duration
// RandomizationFactor sets factor to backoff when buffer pool reaches target size
RandomizationFactor float64
// MaxElapsedTime sets maximum elapsed time to wait during backoff
MaxElapsedTime time.Duration
// WriteBackOff to turn on Backoff for buffer writes
WriteBackOff bool
}
func (src *Options) copyWithDefaults() *Options {
opts := Options{}
if src != nil {
opts = *src
}
if opts.MaxPoolSize == 0 {
opts.MaxPoolSize = maxPoolSize
}
if opts.InitialInterval == 0 {
opts.InitialInterval = DefaultInitialInterval
}
if opts.RandomizationFactor == 0 {
opts.RandomizationFactor = DefaultRandomizationFactor
}
if opts.MaxElapsedTime == 0 {
opts.MaxElapsedTime = DefaultMaxElapsedTime
}
return &opts
}