-
Notifications
You must be signed in to change notification settings - Fork 25
/
option.go
59 lines (50 loc) · 1.25 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
package gopool
import (
"sync"
"time"
)
// Option represents an option for the pool.
type Option func(*goPool)
// WithLock sets the lock for the pool.
func WithLock(lock sync.Locker) Option {
return func(p *goPool) {
p.lock = lock
p.cond = sync.NewCond(p.lock)
}
}
// WithMinWorkers sets the minimum number of workers for the pool.
func WithMinWorkers(minWorkers int) Option {
return func(p *goPool) {
p.minWorkers = minWorkers
}
}
// WithTimeout sets the timeout for the pool.
func WithTimeout(timeout time.Duration) Option {
return func(p *goPool) {
p.timeout = timeout
}
}
// WithResultCallback sets the result callback for the pool.
func WithResultCallback(callback func(interface{})) Option {
return func(p *goPool) {
p.resultCallback = callback
}
}
// WithErrorCallback sets the error callback for the pool.
func WithErrorCallback(callback func(error)) Option {
return func(p *goPool) {
p.errorCallback = callback
}
}
// WithRetryCount sets the retry count for the pool.
func WithRetryCount(retryCount int) Option {
return func(p *goPool) {
p.retryCount = retryCount
}
}
// WithTaskQueueSize sets the size of the task queue for the pool.
func WithTaskQueueSize(size int) Option {
return func(p *goPool) {
p.taskQueueSize = size
}
}