Documentation
¶
Overview ¶
Package connection manages cached client connections to gRPC servers.
Index ¶
Constants ¶
const DEFAULT = ""
DEFAULT is the name of the dialer that is used if not explicitly specified in Connection.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dial ¶
type Dial func(ctx context.Context, target string, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)
Dial defines a function to dial the gRPC connection.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides functionality for creating cached client gRPC connections.
func NewManager ¶
func NewManager(opts ...grpc.DialOption) (*Manager, error)
NewManager creates a new Manager. The opts arguments are used to dial new gRPC targets, with the same semantics as grpc.DialContext.
func NewManagerCustom ¶
NewManagerCustom creates a new Manager. The opts arguments are used to dial new gRPC targets, using the provided Dial function.
func (*Manager) Connection ¶
func (m *Manager) Connection(ctx context.Context, addr, dialer string) (conn *grpc.ClientConn, done func(), err error)
Connection creates a new grpc.ClientConn to the destination address or returns the existing connection, along with a done function.
Usage is registered when a connection is retrieved using Connection. Clients should call the returned done function when the returned connection handle is unused. Subsequent calls to the same done function have no effect. If an error is returned, done has no effect. Connections with no usages will be immediately closed and removed from Manager.
If there is already a pending connection attempt for the same addr, Connection blocks until that attempt finishes and returns a shared result. Note that canceling the context of a pending attempt early would propagate an error to blocked callers.