Close will shutdown the pool and close all existing resources.
()
| 81 | |
| 82 | // Close will shutdown the pool and close all existing resources. |
| 83 | func (p *Pool) Close() { |
| 84 | // Secure this operation with the Release operation. |
| 85 | p.m.Lock() |
| 86 | defer p.m.Unlock() |
| 87 | |
| 88 | // If the pool is already close, don't do anything. |
| 89 | if p.closed { |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | // Set the pool as closed. |
| 94 | p.closed = true |
| 95 | |
| 96 | // Close the channel before we drain the channel of its |
| 97 | // resources. If we don't do this, we will have a deadlock. |
| 98 | close(p.resources) |
| 99 | |
| 100 | // Close the resources |
| 101 | for r := range p.resources { |
| 102 | r.Close() |
| 103 | } |
| 104 | } |