connection

package
v0.0.0-...-aed1ee4 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package connection manages cached client connections to gRPC servers.

Index

Constants

This section is empty.

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

func NewManagerCustom(d Dial, opts ...grpc.DialOption) (*Manager, error)

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 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.

Jump to

Keyboard shortcuts

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