goConnectPool
1.0.0
A Go Net.Conn Pool pour Golang. Inspiré par le pool (FATIH / Pool), ajoutez du code et de la fonction pour limiter les numéros de connexion actifs.
go get github.com/dubin555/goConnectPoolVeuillez vous assurer d'utiliser le code de branche Master.
// 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 ()