-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoption.go
36 lines (31 loc) · 871 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
package racegroup
import "errors"
// A Option is a functional option that changes the behavior of Group.
type Option func(*Group) error
// ErrorHandler returns an Option that sets the error handler.
func ErrorHandler(handler func(error)) Option {
return func(g *Group) error {
g.errHandler = handler
return nil
}
}
// Concurrency returns an Option that sets number of concurrency for goroutines.
func Concurrency(i int) Option {
return func(g *Group) error {
if i < 1 {
return errors.New("concurrency option must be greater than zero")
}
g.semaphore = make(chan struct{}, i)
return nil
}
}
// Desired returns an Option that sets number of desired completed tasks.
func Desired(i int) Option {
return func(g *Group) error {
if i < 1 {
return errors.New("desired option must be greater than zero")
}
g.desired = int64(i)
return nil
}
}