概述
我们知道,Go 语言已经提供了 sync.Pool
,但是做的不怎么好,所以有必要来实现一个 Pool
代码
type Pool struct {
pool chan *Client
}
// Create a new Pool
func NewPool(max int) *Pool{
return &Pool{
pool: make(chan *Client, max)
}
}
// Get a Client from Pool
func (p *Pool) Borrow() *Client {
var cl *Client