(timeout time.Duration)
| 78 | } |
| 79 | |
| 80 | func (p *Pool) get(timeout time.Duration) *client { |
| 81 | select { |
| 82 | case c := <-p.clients: |
| 83 | return c |
| 84 | default: |
| 85 | } |
| 86 | |
| 87 | if p.created < p.max { |
| 88 | p.makeOne() |
| 89 | } |
| 90 | |
| 91 | var deadline <-chan time.Time |
| 92 | if timeout >= 0 { |
| 93 | deadline = time.After(timeout) |
| 94 | } |
| 95 | |
| 96 | for { |
| 97 | select { |
| 98 | case c := <-p.clients: |
| 99 | return c |
| 100 | case <-p.rebuild: |
| 101 | p.makeOne() |
| 102 | case <-deadline: |
| 103 | return nil |
| 104 | case <-p.closing: |
| 105 | return nil |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func shouldReuse(err error) bool { |
| 111 | // certainly not perfect, but might be close: |