-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
40 lines (34 loc) · 1.26 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
package komi
// poolWork is an internal function type to set pool's work performer.
type poolWork[I, O any] func(p *Pool[I, O])
// noValue is an internal type used to indicate whether a pool is producing
// outputs or not. So if output's type is `noValue`, then no outputs are made.
type noValue any
// WorkSimple should be used to set work with no outputs nor errors.
func WorkSimple[I any](work func(I)) poolWork[I, noValue] {
return func(p *Pool[I, noValue]) {
p.workSimple = work
p.workPerformer = p.performWorkSimple
}
}
// WorkSimpleWithErrors should be used to set work with no outputs but with errors.
func WorkSimpleWithErrors[I any](work func(I) error) poolWork[I, noValue] {
return func(p *Pool[I, noValue]) {
p.workSimpleWithErrors = work
p.workPerformer = p.performWorkSimpleWithErrors
}
}
// Work should be used to set work with outputs but no errors.
func Work[I, O any](work func(I) O) poolWork[I, O] {
return func(p *Pool[I, O]) {
p.workRegular = work
p.workPerformer = p.performWorkRegular
}
}
// WorkWithErrors should be used to set work with both outputs and errors.
func WorkWithErrors[I, O any](work func(I) (O, error)) poolWork[I, O] {
return func(p *Pool[I, O]) {
p.workRegularWithErrors = work
p.workPerformer = p.performWorkWithErrors
}
}