Skip to content

dubin555/goConnectPool

Repository files navigation

goConnectPool

Build Status Go Report Card Project Status Coverage Status

What is goConnectPool

A go net.conn pool for Golang. Inspired by the Pool(fatih/pool), add some code and function for limit the active connection numbers.

Install and Usage

go get github.com/dubin555/goConnectPool

Please make sure you use the master branch code.

Example

// a factory func to generate a net connection.
factory := func() (net.Conn, error) { return net.Dial("tcp", "127.0.0.1:9999") }

// create a new channel based pool with an initial capacity of 5, maximum capacity of 30,
// and maximum actives of 15.
pool, err := pool.NewChannelPool(5, 30, 15, factory)

// get a connection from the pool, non blocking mode, if reach the limit, return nil instead. 

// Block Mode
conn, err := pool.Get()

// balabalabala
// close the conn, will release the conn to the pool by calling Close()
conn.Close()

// Non Blocking Mode, will return nil when no permission
conn, err := pool.TryGet()

// close the pool
pool.Close()

// return the connections length
p.Len()

// return the current active permissions
p.LenActives()

About

A simple Golang net connection pool

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages