Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTimeout = errors.New("timeout")
ErrTimeout represents a timeout error, for example you called Get and couldn't get a connection within the timeout period.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Name is a friendly name associated with the pool, cab be useful for debugging Name string // Size is the number of connections to open Size int // RetryDuration specifies how long the pool will wait to try to create a new connection // if the previous new conneciton attempt failed RetryDuration time.Duration // NewConnection takes in the pool config information and returns an open net.Conn connection // that can be added to the pool. NewConnection func(Config) (net.Conn, error) }
Config contains all of the configuration parameters for the connection pool
type Connection ¶
Connection represents a connection to a network resource
func NewConnection ¶
func NewConnection(c net.Conn, p *ConnectionPool) *Connection
NewConnection returns an initialized Connection instance
func (*Connection) Close ¶
func (c *Connection) Close() error
Close returns the connection to the pool, the connection stays open
type ConnectionPool ¶
type ConnectionPool struct { Config Config // contains filtered or unexported fields }
ConnectionPool provides the ability to pool connections
func NewPool ¶
func NewPool(config Config) *ConnectionPool
NewPool creates a new ConnectionPool. The pool which is returned will still need to have Init() called in it before it can be used
func (*ConnectionPool) Close ¶
func (p *ConnectionPool) Close() chan bool
Close closes all of the underlying connections, this is non blocking but you can wait on the returned channel if you need to know all the connections have closed
func (*ConnectionPool) Get ¶
func (p *ConnectionPool) Get(timeout time.Duration, flush bool) (*Connection, error)
Get is a blocking function that waits to get an available connection. If after the timeout duration a connection could not be fetched, the function returns with ErrTimeout. The flush parameter if set to true will read all of the outstanding data from the connection before returning it to the caller. Note there is a possible 100ms delay for this function to return if you set flush==true while the pool tries to read any existing content from the connection
func (*ConnectionPool) Init ¶
func (p *ConnectionPool) Init() chan bool
Init should be called before using the pool, the call is non blocking, but you can wait on the returned channel if you want to know when all of the underlying connections have been created and are ready to use
func (*ConnectionPool) Release ¶
func (p *ConnectionPool) Release(c *Connection, err error)
Release returns the connection back to the pool. err is any error that was returned by the connection while it was being used, if there was an error the pool will then throw this connection away and create a new one