Skip to content

Installation and Quick Start

Terminal window
go get github.com/iyashjayesh/go-adaptive-pool

The core has no dependency on Prometheus or OpenTelemetry. The metrics adapters are separate modules; add the one you use:

Terminal window
go get github.com/iyashjayesh/go-adaptive-pool/promrecorder # Prometheus
go get github.com/iyashjayesh/go-adaptive-pool/otelrecorder # OpenTelemetry

Here is a simple example of how to create a pool and submit a job.

package main
import (
"context"
"log"
"time"
"github.com/iyashjayesh/go-adaptive-pool"
)
func main() {
// creating pool
pool, err := adaptivepool.New(
adaptivepool.WithMinWorkers(4),
adaptivepool.WithMaxWorkers(32),
adaptivepool.WithQueueSize(1000),
)
if err != nil {
log.Fatal(err)
}
defer pool.Shutdown(context.Background())
// Submit job
job := func(ctx context.Context) error {
// Your work here
time.Sleep(100 * time.Millisecond)
return nil
}
if err := pool.Submit(context.Background(), job); err != nil {
log.Printf("Failed to Submit: %v", err)
}
}