github.com/jackc/puddle@v1.3.0/README.md (about)

     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  
     6  Puddle is a tiny generic resource pool library for Go that uses the standard
     7  context library to signal cancellation of acquires. It is designed to contain
     8  the minimum functionality required for a resource pool. It can be used directly
     9  or it can be used as the base for a domain specific resource pool. For example,
    10  a database connection pool may use puddle internally and implement health checks
    11  and keep-alive behavior without needing to implement any concurrent code of its
    12  own.
    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
    25  constructor := func(context.Context) (interface{}, error) {
    26    return net.Dial("tcp", "127.0.0.1:8080")
    27  }
    28  destructor := func(value interface{}) {
    29    value.(net.Conn).Close()
    30  }
    31  maxPoolSize := 10
    32  
    33  pool := puddle.NewPool(constructor, destructor, maxPoolSize)
    34  
    35  // Acquire resource from the pool.
    36  res, err := pool.Acquire(context.Background())
    37  if err != nil {
    38    // ...
    39  }
    40  
    41  // Use resource.
    42  _, err = res.Value().(net.Conn).Write([]byte{1})
    43  if err != nil {
    44    // ...
    45  }
    46  
    47  // Release when done.
    48  res.Release()
    49  
    50  ```
    51  
    52  ## Status
    53  
    54  Puddle 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  
    62  MIT