New creates a pool that manages resources. A pool requires a function that can allocate a new resource and the size of the pool.
(fn func() (io.Closer, error), size uint)
| 27 | // function that can allocate a new resource and the size of |
| 28 | // the pool. |
| 29 | func New(fn func() (io.Closer, error), size uint) (*Pool, error) { |
| 30 | if size <= 0 { |
| 31 | return nil, errors.New("Size value too small.") |
| 32 | } |
| 33 | |
| 34 | return &Pool{ |
| 35 | factory: fn, |
| 36 | resources: make(chan io.Closer, size), |
| 37 | }, nil |
| 38 | } |
| 39 | |
| 40 | // Acquire retrieves a resource from the pool. |
| 41 | func (p *Pool) Acquire() (io.Closer, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected