Release Notes for v0.1.0
Initial release of go-pooler
.
Overview
go-pooler
is a simple and generic resource pooler for managing reusable resources in Go. It is designed to handle resource acquisition, release, and health checks efficiently, making it suitable for high-concurrency applications.
Features
- Acquiring and Releasing Resources by Key: Manage resources using unique keys.
- Configurable Maximum Number of Open Resources: Limit the number of open resources.
- Periodic Health Checks: Automatically perform health checks and resource cleanup at configurable intervals.
- Pool Statistics: Gather statistics about the pool's usage, such as the number of open resources and wait times.
Installation
To install the package, use:
go get github.com/bartventer/go-pooler
Basic Usage
To create a new pool, define a resource that implements the Reusable interface and use the NewPool function:
package main
import (
"context"
"github.com/bartventer/go-pooler"
)
type Worker struct{}
type WorkerPool = pooler.Pool[*Worker]
func (w *Worker) Close() error { return nil }
func (w *Worker) PingContext(ctx context.Context) error { return nil }
func WorkerFactory() (*Worker, error) {
return &Worker{}, nil
}
func NewWorkerPool(ctx context.Context, opts ...pooler.Option) *WorkerPool {
return pooler.NewPool(ctx, WorkerFactory, opts...)
}
func main() {
ctx := context.Background()
p := NewWorkerPool(ctx, pooler.WithMaxOpenResources(1))
_, err := p.Acquire(ctx, "key1")
if err != nil {
panic(err)
}
defer p.Release("key1")
// Use the worker...
}
Documentation
Refer to the GoDoc for detailed documentation and examples.
We hope you find go-pooler
useful for your projects. Please feel free to open issues or contribute to the repository.
Full Changelog: https://github.com/bartventer/go-pooler/commits/v0.1.0