Files
marketlabtest/worker/pool.go
2024-05-30 19:42:26 +03:00

43 lines
681 B
Go

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
}