pool

Connection pool for Go's net.Conn interface

  • 所有者: fatih/pool
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Archived project. No maintenance.

This project is not maintained anymore and is archived. Feel free to fork and
use make your own changes if needed.

Thanks all for their work on this project.

Pool GoDoc Build Status

Pool is a thread safe connection pool for net.Conn interface. It can be used to
manage and reuse connections.

Install and Usage

Install the package with:

go get github.com/fatih/pool

Please vendor the package with one of the releases: https://github.com/fatih/pool/releases.
master branch is development branch and will contain always the latest changes.

Example

// create a factory() to be used with channel based pool
factory    := func() (net.Conn, error) { return net.Dial("tcp", "127.0.0.1:4000") }

// create a new channel based pool with an initial capacity of 5 and maximum
// capacity of 30. The factory will create 5 initial connections and put it
// into the pool.
p, err := pool.NewChannelPool(5, 30, factory)

// now you can get a connection from the pool, if there is no connection
// available it will create a new one via the factory function.
conn, err := p.Get()

// do something with conn and put it back to the pool by closing the connection
// (this doesn't close the underlying connection instead it's putting it back
// to the pool).
conn.Close()

// close the underlying connection instead of returning it to pool
// it is useful when acceptor has already closed connection and conn.Write() returns error
if pc, ok := conn.(*pool.PoolConn); ok {
  pc.MarkUnusable()
  pc.Close()
}

// close pool any time you want, this closes all the connections inside a pool
p.Close()

// currently available connections in the pool
current := p.Len()

Credits

License

The MIT License (MIT) - see LICENSE for more details

主要指标

概览
名称与所有者fatih/pool
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2013-11-28 14:02:50
推送于2018-07-22 10:02:14
最后一次提交2018-07-22 13:01:58
发布数3
最新版本名称v3.0.0 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数1.4k
关注者数44
派生数292
提交数66
已启用问题?
问题数12
打开的问题数0
拉请求数10
打开的拉请求数0
关闭的拉请求数7
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?