Documentation
¶
Index ¶
- func NewExponentialBackoff(baseDelay, maxDelay uint) backoff.Backoff
- func NewFibonacciBackoff(maxDelay uint) backoff.Backoff
- func NewFixedBackoff(interval uint) backoff.Backoff
- func NewLinearBackoff(scalar uint) backoff.Backoff
- func NewPolynomialBackoff(exponent uint) backoff.Backoff
- type Config
- type Pool
- type PoolHooks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewExponentialBackoff ¶
NewExponentialBackoff creates a new exponential backoff strategy. The delay between retries doubles with each attempt until reaching the maximum delay.
Parameters:
- baseDelay: The initial delay in seconds for the first retry.
- maxDelay: The maximum delay in seconds for retries.
Returns:
- A backoff.Backoff implementation using exponential backoff.
func NewFibonacciBackoff ¶
NewFibonacciBackoff creates a new Fibonacci backoff strategy. The delay between retries follows the Fibonacci sequence until reaching the maximum delay.
Parameters:
- maxDelay: The maximum delay in seconds for retries.
Returns:
- A backoff.Backoff implementation using Fibonacci backoff.
func NewFixedBackoff ¶
NewFixedBackoff creates a new fixed backoff strategy. The delay between retries remains constant.
Parameters:
- interval: The fixed delay in seconds between retries.
Returns:
- A backoff.Backoff implementation using fixed backoff.
func NewLinearBackoff ¶
NewLinearBackoff creates a new linear backoff strategy. The delay between retries increases linearly with each attempt.
Parameters:
- scalar: The constant value added to the delay for each retry.
Returns:
- A backoff.Backoff implementation using linear backoff.
func NewPolynomialBackoff ¶
NewPolynomialBackoff creates a new polynomial backoff strategy. The delay between retries follows a polynomial growth pattern.
Parameters:
- exponent: The exponent used for calculating delay growth.
Returns:
- A backoff.Backoff implementation using polynomial backoff.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents the configuration for a connection pool. It encapsulates various settings like connection limits, timeouts, retries, backoff strategies, and event hooks.
func NewConfig ¶
func NewConfig( address, name string, maxConnections int, connTimeout, idleTimeout time.Duration, maxRetries uint, backoff backoff.Backoff, hooks PoolHooks, ) *Config
NewConfig creates a new Config object with the specified parameters.
Parameters:
- address: The network address for the pool's connections.
- name: A custom name for the pool (if empty, it's generated based on the address).
- maxConnections: The maximum number of active connections in the pool.
- connTimeout: The timeout for establishing new connections.
- idleTimeout: The timeout for cleaning up idle connections.
- maxRetries: The maximum number of retries for failed connections.
- backoff: The backoff strategy for retrying failed connections.
- hooks: A set of custom hooks for pool events.
Returns:
- A pointer to the created Config object.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a connection pool that manages TCP connections. It provides methods to acquire and release connections, as well as to fetch them asynchronously.
func New ¶
New creates a new Pool instance based on the given configuration. It initializes an internal connection pool and returns a Pool object.
Parameters:
- c: A Config object containing the pool configuration.
Returns:
- A pointer to the created Pool.
- An error, if the pool initialization fails.
func (*Pool) Get ¶
Get retrieves a connection from the pool. If an idle connection is available, it is returned; otherwise, a new connection is created.
Returns:
- A net.Conn representing the connection.
- An error, if the connection retrieval fails.
func (*Pool) GetAsync ¶
GetAsync retrieves a connection from the pool asynchronously. It returns a channel through which the result (connection or error) will be sent once available.
Returns:
- A read-only channel of a struct containing:
- Conn: A net.Conn representing the connection.
- Err: An error, if the connection retrieval fails.
type PoolHooks ¶
type PoolHooks struct {
// OnConnectionCreate is triggered when a new connection is created.
OnConnectionCreate func(conn net.Conn)
// OnConnectionAcquire is triggered when a connection is acquired from the pool.
OnConnectionAcquire func(conn net.Conn)
// OnConnectionRelease is triggered when a connection is released back into the pool.
OnConnectionRelease func(conn net.Conn)
// OnConnectionClose is triggered when a connection is closed.
OnConnectionClose func(conn net.Conn)
// OnConnectionError is triggered when an error occurs during connection operations.
OnConnectionError func(err error)
// OnPoolCreate is triggered when the connection pool is successfully created.
OnPoolCreate func(c Config)
// OnPoolCreateError is triggered when there is an error during pool creation.
OnPoolCreateError func(err error)
}
PoolHooks defines callback functions that can be triggered during various connection pool events. These hooks allow custom logic to be executed during connection creation, acquisition, release, closure, errors, or during pool creation.
func (PoolHooks) ToInternal ¶
ToInternal converts a public PoolHooks object to the corresponding internal representation. This is used to pass hooks from the public API to the internal pool implementation.