-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
39 lines (31 loc) · 853 Bytes
/
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
package goasync
import "time"
type Option interface {
apply(k *keeper)
}
type OptionFunc func(k *keeper)
func (f OptionFunc) apply(k *keeper) { f(k) }
// WithErrorHandlerOption returns a function which sets handler for the error.
func WithErrorHandlerOption(f ErrorHandler) OptionFunc {
return func(k *keeper) {
k.errorHandler = f
}
}
// WithQueueSizeOption returns a function which sets queue size.
func WithQueueSizeOption(size int) OptionFunc {
return func(k *keeper) {
k.queueSize = size
}
}
// WithWorkerSizeOption returns a function which sets worker size.
func WithWorkerSizeOption(size int) OptionFunc {
return func(k *keeper) {
k.workerSize = size
}
}
// WithTimeoutOption returns a function which set timeout.
func WithTimeoutOption(timeout time.Duration) OptionFunc {
return func(k *keeper) {
k.timeout = timeout
}
}