GitXplorerGitXplorer
f

pool

public
1363 stars
292 forks
0 issues

Commits

List of commits on branch master.
Unverified
d817ebe42acfb2147a68af2007324c3492260c4a

Closing yet another chapter in my life.

ffatih committed 6 years ago
Verified
830a0f4759206ca695bc91927303867a1ba951bc

Merge pull request #25 from lrita/v2.0.0

ffatih committed 7 years ago
Unverified
f83b9d975e4dbf8d73f9abeae43caa3bd654b9cb

Update README.md

ffatih committed 7 years ago
Unverified
5abcdf4c427e817ecb5b272b235a8356e6f85674

using sync.RWMutex instead of sync.Mutex in channelPool.

llrita committed 7 years ago
Unverified
010e0b745d12eaf8426c95f9c3924d81dd0b668f

Merge pull request #20 from lrita/v2.0.0

ffatih committed 7 years ago
Unverified
7e0c3aba5da970d4e1907fecb07310b7db5f1466

Merge pull request #21 from atsushi-ishibashi/update-readme

ffatih committed 7 years ago

README

The README file for this repository.

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