https://github.com/bartventer/go-pooler
Generic resource pooler for managing reusable resources in Go. Handle resource acquisition, release, and health checks efficiently. Suitable for high-concurrency applications.
https://github.com/bartventer/go-pooler
go golang pooling resource-pool
Last synced: 2 months ago
JSON representation
Generic resource pooler for managing reusable resources in Go. Handle resource acquisition, release, and health checks efficiently. Suitable for high-concurrency applications.
- Host: GitHub
- URL: https://github.com/bartventer/go-pooler
- Owner: bartventer
- License: apache-2.0
- Created: 2024-08-16T14:59:08.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-11-25T06:27:22.000Z (7 months ago)
- Last Synced: 2024-12-24T10:37:31.226Z (6 months ago)
- Topics: go, golang, pooling, resource-pool
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-pooler
[](https://pkg.go.dev/github.com/bartventer/go-pooler)
[](https://github.com/bartventer/go-pooler/releases/latest)
[](https://goreportcard.com/report/github.com/bartventer/go-pooler)
[](https://codecov.io/gh/bartventer/go-pooler)
[](https://github.com/bartventer/go-pooler/actions/workflows/default.yml)

[](LICENSE)The `go-pooler` package provides 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:
```bash
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:
```go
package mainimport (
"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](https://pkg.go.dev/github.com/bartventer/go-pooler) for detailed documentation and examples.
## License
This project is licensed under the Apache License, Version 2.0 - see the [LICENSE](LICENSE) file for details.