goConnectPool
1.0.0
GOLANG을위한 GO NET.CONN POOL. 수영장에서 영감을 얻은 (Fatih/Pool), 활성 연결 번호를 제한하기위한 코드와 기능을 추가하십시오.
go get github.com/dubin555/goConnectPool마스터 브랜치 코드를 사용해야합니다.
// 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 ()