2023-01-05 12:45:09 +01:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
2023-01-11 09:13:59 +01:00
|
|
|
"context"
|
2023-01-05 12:45:09 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/alitto/pond"
|
|
|
|
)
|
|
|
|
|
2023-03-08 15:30:40 +01:00
|
|
|
const (
|
|
|
|
idleTimeout = 1 * time.Second
|
|
|
|
)
|
|
|
|
|
2023-01-05 12:45:09 +01:00
|
|
|
type Opts struct {
|
2023-01-18 20:40:14 +01:00
|
|
|
Concurrency int
|
|
|
|
QueueSize int
|
2023-01-05 12:45:09 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 09:13:59 +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(
|
2023-01-18 20:40:14 +01:00
|
|
|
o.Concurrency,
|
|
|
|
o.QueueSize,
|
|
|
|
pond.MinWorkers(o.Concurrency),
|
2023-03-08 15:30:40 +01:00
|
|
|
pond.IdleTimeout(idleTimeout),
|
2023-01-11 09:13:59 +01:00
|
|
|
pond.Context(ctx),
|
2023-01-05 12:45:09 +01:00
|
|
|
)
|
|
|
|
}
|