2024-05-23 08:41:39 +02:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log/slog"
|
|
|
|
"runtime/debug"
|
|
|
|
|
|
|
|
"github.com/alitto/pond"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PoolOpts struct {
|
2024-06-20 08:19:06 +02:00
|
|
|
Logg *slog.Logger
|
|
|
|
WorkerCount int
|
|
|
|
BlocksBuffer int
|
2024-05-23 08:41:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPool(o PoolOpts) *pond.WorkerPool {
|
|
|
|
return pond.New(
|
|
|
|
o.WorkerCount,
|
2024-06-20 08:19:06 +02:00
|
|
|
o.BlocksBuffer,
|
2024-05-23 08:41:39 +02:00
|
|
|
pond.Strategy(pond.Balanced()),
|
|
|
|
pond.PanicHandler(panicHandler(o.Logg)),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func panicHandler(logg *slog.Logger) func(interface{}) {
|
|
|
|
return func(panic interface{}) {
|
|
|
|
logg.Error("block processor goroutine exited from a panic", "error", panic, "stack_trace", string(debug.Stack()))
|
|
|
|
}
|
|
|
|
}
|