cic-chain-events/internal/pool/pool.go

29 lines
445 B
Go
Raw Normal View History

2023-01-05 12:45:09 +01:00
package pool
import (
"context"
2023-01-05 12:45:09 +01:00
"time"
"github.com/alitto/pond"
)
const (
idleTimeout = 1 * time.Second
)
2023-01-05 12:45:09 +01:00
type Opts struct {
Concurrency int
QueueSize int
2023-01-05 12:45:09 +01:00
}
// NewPool creates a fixed size (and buffered) go routine worker pool.
func NewPool(ctx context.Context, o Opts) *pond.WorkerPool {
2023-01-05 12:45:09 +01:00
return pond.New(
o.Concurrency,
o.QueueSize,
pond.MinWorkers(o.Concurrency),
pond.IdleTimeout(idleTimeout),
pond.Context(ctx),
2023-01-05 12:45:09 +01:00
)
}