Acquire retrieves a resource from the pool.
()
| 39 | |
| 40 | // Acquire retrieves a resource from the pool. |
| 41 | func (p *Pool) Acquire() (io.Closer, error) { |
| 42 | select { |
| 43 | // Check for a free resource. |
| 44 | case r, ok := <-p.resources: |
| 45 | log.Println("Acquire:", "Shared Resource") |
| 46 | if !ok { |
| 47 | return nil, ErrPoolClosed |
| 48 | } |
| 49 | return r, nil |
| 50 | |
| 51 | // Provide a new resource since there are none available. |
| 52 | default: |
| 53 | log.Println("Acquire:", "New Resource") |
| 54 | return p.factory() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // Release places a new resource onto the pool. |
| 59 | func (p *Pool) Release(r io.Closer) { |