Initial commit
This commit is contained in:
42
worker/pool.go
Normal file
42
worker/pool.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func NewPool(in <-chan [10]int, workersNum uint, log *zap.Logger) *Pool {
|
||||
out := make(chan [3]int, workersNum)
|
||||
|
||||
return &Pool{
|
||||
in: in,
|
||||
out: out,
|
||||
workersNum: int(workersNum),
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
type Pool struct {
|
||||
in <-chan [10]int
|
||||
out chan [3]int
|
||||
|
||||
workersNum int
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
func (p *Pool) Start(ctx context.Context, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
wg.Add(p.workersNum)
|
||||
|
||||
for i := 0; i < p.workersNum; i++ {
|
||||
go NewWorker(p.in, p.out, p.log.Named(fmt.Sprintf("worker_%d", i))).Start(ctx, wg)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pool) Out() <-chan [3]int {
|
||||
return p.out
|
||||
}
|
||||
Reference in New Issue
Block a user