...

Text file src/github.com/jackc/puddle/README.md

Documentation: github.com/jackc/puddle

     1[![](https://godoc.org/github.com/jackc/puddle?status.svg)](https://godoc.org/github.com/jackc/puddle)
     2![Build Status](https://github.com/jackc/puddle/actions/workflows/ci.yml/badge.svg)
     3
     4# Puddle
     5
     6Puddle is a tiny generic resource pool library for Go that uses the standard
     7context library to signal cancellation of acquires. It is designed to contain
     8the minimum functionality required for a resource pool. It can be used directly
     9or it can be used as the base for a domain specific resource pool. For example,
    10a database connection pool may use puddle internally and implement health checks
    11and keep-alive behavior without needing to implement any concurrent code of its
    12own.
    13
    14## Features
    15
    16* Acquire cancellation via context standard library
    17* Statistics API for monitoring pool pressure
    18* No dependencies outside of standard library
    19* High performance
    20* 100% test coverage
    21
    22## Example Usage
    23
    24```go
    25constructor := func(context.Context) (interface{}, error) {
    26  return net.Dial("tcp", "127.0.0.1:8080")
    27}
    28destructor := func(value interface{}) {
    29  value.(net.Conn).Close()
    30}
    31maxPoolSize := 10
    32
    33pool := puddle.NewPool(constructor, destructor, maxPoolSize)
    34
    35// Acquire resource from the pool.
    36res, err := pool.Acquire(context.Background())
    37if err != nil {
    38  // ...
    39}
    40
    41// Use resource.
    42_, err = res.Value().(net.Conn).Write([]byte{1})
    43if err != nil {
    44  // ...
    45}
    46
    47// Release when done.
    48res.Release()
    49
    50```
    51
    52## Status
    53
    54Puddle v1 is complete. No changes are planned.
    55
    56* Bug reports and fixes are welcome.
    57* New features will not be accepted if they can be feasibly implemented in a wrapper.
    58* Performance optimizations will not be accepted unless the performance issue rises to the level of a bug.
    59
    60## License
    61
    62MIT

View as plain text