-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker-pool-task.go
More file actions
52 lines (47 loc) · 1.1 KB
/
worker-pool-task.go
File metadata and controls
52 lines (47 loc) · 1.1 KB
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
package pants
// the Job is implied by the I and O specified, so
// Job[I] is derived from WorkerPool[I]
// JobOutput[O] is derived from WorkerPool[O]
//
// Unit of Work schemes:
//
// * Simple: this is the native ants format
// Simple: func()
// SimpleE: func() error
//
// * Input: input only
// Input: func[I any]()
// InputE: func[I any]() error
//
// * Output: output only, is this really useful?
// Output: func[O any]() O
// OutputE: func[O any]() O, error
//
// * Manifold: with input and output
// Manifold: func[I, O any]() O
// ManifoldE: func[I, O any]() O, error
//
import (
"context"
"github.com/snivilised/pants/internal/third/ants"
)
type TaskPool[I, O any] struct {
basePool[I, O]
taskPool
}
// NewTaskPool creates a new worker pool using the native ants interface; ie
// new jobs are submitted with Submit(task TaskFunc)
func NewTaskPool[I, O any](ctx context.Context,
wg WaitGroup,
options ...Option,
) (*TaskPool[I, O], error) {
pool, err := ants.NewPool(ctx, options...)
return &TaskPool[I, O]{
basePool: basePool[I, O]{
wg: wg,
},
taskPool: taskPool{
pool: pool,
},
}, err
}