Add more docs and example
This commit is contained in:
@@ -13,6 +13,36 @@ Puddle is a tiny generic resource pool library for Go that uses the standard con
|
||||
* High performance
|
||||
* 100% test coverage
|
||||
|
||||
## Example Usage
|
||||
|
||||
```go
|
||||
constructor := func(context.Context) (interface{}, error) {
|
||||
return net.Dial("tcp", "127.0.0.1:8080")
|
||||
}
|
||||
destructor := func(value interface{}) {
|
||||
value.(net.Conn).Close()
|
||||
}
|
||||
maxPoolSize := 10
|
||||
|
||||
pool := puddle.NewPool(constructor, destructor, maxPoolSize)
|
||||
|
||||
// Acquire resource from the pool.
|
||||
res, err := pool.Acquire(context.Background())
|
||||
if err != nil {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Use resource.
|
||||
_, err = res.Value().(net.Conn).Write([]byte{1})
|
||||
if err != nil {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Release when done.
|
||||
res.Release()
|
||||
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Reference in New Issue
Block a user