2
0

Add more docs and example

This commit is contained in:
Jack Christensen
2018-12-26 18:36:59 -06:00
parent 893989abad
commit 5cb5ce10c3
3 changed files with 121 additions and 0 deletions
+30
View File
@@ -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