2
0

Add min pool size

This commit is contained in:
Jack Christensen
2018-12-23 16:03:30 -06:00
parent e3d027932a
commit bc74a79c98
3 changed files with 35 additions and 1 deletions
+25
View File
@@ -37,6 +37,7 @@ type Pool struct {
allResources map[interface{}]*resourceWrapper
availableResources []*resourceWrapper
minSize int
maxSize int
closed bool
@@ -84,6 +85,30 @@ func (p *Pool) Size() int {
return n
}
// MinSize returns the current minimum size of the pool.
func (p *Pool) MinSize() int {
p.cond.L.Lock()
n := p.minSize
p.cond.L.Unlock()
return n
}
// SetMinSize sets the minimum size of the pool. It panics if n < 0.
func (p *Pool) SetMinSize(n int) {
if n < 0 {
panic("pool MinSize cannot be < 0")
}
p.cond.L.Lock()
p.minSize = n
for len(p.allResources) < p.minSize {
createResChan, createErrChan := p.startCreate()
p.backgroundFinishCreate(createResChan, createErrChan)
}
p.cond.L.Unlock()
}
// MaxSize returns the current maximum size of the pool.
func (p *Pool) MaxSize() int {
p.cond.L.Lock()