-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
41 lines (36 loc) · 851 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
40
41
package parwork
import (
"errors"
)
// Option defines a option for the processor
type Option func(*Processor) error
// Workers defines a processor option for the workers
func Workers(count int) Option {
return func(p *Processor) error {
if count <= 0 {
return errors.New("worker count must be positive")
}
p.workers = count
return nil
}
}
// Queue defines a processor option for the queue length
func Queue(length int) Option {
return func(p *Processor) error {
if length <= 0 {
return errors.New("queue length must be positive")
}
p.queue = length
return nil
}
}
// Collector defines a processor option for the work collector
func Collector(reporter WorkCollector) Option {
return func(p *Processor) error {
if reporter == nil {
return errors.New("reporter is nil")
}
p.reporter = reporter
return nil
}
}