|
|
@ -19,7 +19,7 @@ type (
|
|
|
|
|
|
|
|
|
|
|
|
// A Pool is used to pool resources.
|
|
|
|
// A Pool is used to pool resources.
|
|
|
|
// The difference between sync.Pool is that:
|
|
|
|
// The difference between sync.Pool is that:
|
|
|
|
// 1. the limit of the resouces
|
|
|
|
// 1. the limit of the resources
|
|
|
|
// 2. max age of the resources can be set
|
|
|
|
// 2. max age of the resources can be set
|
|
|
|
// 3. the method to destroy resources can be customized
|
|
|
|
// 3. the method to destroy resources can be customized
|
|
|
|
Pool struct {
|
|
|
|
Pool struct {
|
|
|
@ -56,7 +56,7 @@ func NewPool(n int, create func() interface{}, destroy func(interface{}), opts .
|
|
|
|
return pool
|
|
|
|
return pool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get gets a resouce.
|
|
|
|
// Get gets a resource.
|
|
|
|
func (p *Pool) Get() interface{} {
|
|
|
|
func (p *Pool) Get() interface{} {
|
|
|
|
p.lock.Lock()
|
|
|
|
p.lock.Lock()
|
|
|
|
defer p.lock.Unlock()
|
|
|
|
defer p.lock.Unlock()
|
|
|
|