connection

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package connection manages (abstract) connections with retrying and reconnection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UsingConnection added in v0.13.0

func UsingConnection[T any](ctx context.Context, r *Reconnector, desc string, cb func(cli Connection) (T, error)) (T, error)

UsingConnection invokes the provided callback for a Connection.

Types

type Connection

type Connection interface {
	fmt.Stringer
	io.Closer
}

Connection encapsulates a single connection.

type ConnectorImpl

type ConnectorImpl interface {
	NewConnection(ctx context.Context) (Connection, error)
	IsConnectionClosedError(err error) bool
}

ConnectorImpl provides a set of methods to manage connections.

type Reconnector

type Reconnector struct {
	// contains filtered or unexported fields
}

Reconnector manages active Connection with automatic retrying and reconnection.

func NewReconnector

func NewReconnector(conn ConnectorImpl) *Reconnector

NewReconnector creates a new Pool for a given connector.

func (*Reconnector) CloseActiveConnection

func (r *Reconnector) CloseActiveConnection(ctx context.Context)

CloseActiveConnection closes the active connection if any.

func (*Reconnector) GetOrOpenConnection

func (r *Reconnector) GetOrOpenConnection(ctx context.Context) (Connection, error)

GetOrOpenConnection gets or establishes new connection and returns it.

func (*Reconnector) UsingConnectionNoResult

func (r *Reconnector) UsingConnectionNoResult(ctx context.Context, desc string, cb func(cli Connection) error) error

UsingConnectionNoResult invokes the provided callback for a Connection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL