Release places a new resource onto the pool.
(r io.Closer)
| 57 | |
| 58 | // Release places a new resource onto the pool. |
| 59 | func (p *Pool) Release(r io.Closer) { |
| 60 | // Secure this operation with the Close operation. |
| 61 | p.m.Lock() |
| 62 | defer p.m.Unlock() |
| 63 | |
| 64 | // If the pool is closed, discard the resource. |
| 65 | if p.closed { |
| 66 | r.Close() |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | select { |
| 71 | // Attempt to place the new resource on the queue. |
| 72 | case p.resources <- r: |
| 73 | log.Println("Release:", "In Queue") |
| 74 | |
| 75 | // If the queue is already at cap we close the resource. |
| 76 | default: |
| 77 | log.Println("Release:", "Closing") |
| 78 | r.Close() |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Close will shutdown the pool and close all existing resources. |
| 83 | func (p *Pool) Close() { |
no test coverage detected