rpc

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNoMoreClient = errors.New("no more clients")

Functions

func Sort added in v1.6.8

func Sort[C any](ctx context.Context, clients *Clients[C], sortValueFetch SortValueFetcher[C], direction SortDirection) error

func WithClients

func WithClients[C any, V any](clients *Clients[C], f func(context.Context, C) (v V, err error)) (v V, err error)

func WithClientsContext added in v1.9.11

func WithClientsContext[C any, V any](clients *Clients[C], ctx context.Context, f func(context.Context, C) (v V, err error)) (v V, err error)

Types

type Clients

type Clients[C any] struct {
	// contains filtered or unexported fields
}

func NewClients

func NewClients[C any](maxBlockFetchDuration time.Duration, rollingStrategy RollingStrategy[C], logger *zap.Logger) *Clients[C]

func (*Clients[C]) Add

func (c *Clients[C]) Add(client C)

Add appends a client to the pool, giving it the auto-generated provider name `client-<index>` where `<index>` is its position in the pool. Use Clients.AddNamed to give the client a meaningful name, which is then reported in errors and logs.

func (*Clients[C]) AddNamed added in v1.17.0

func (c *Clients[C]) AddNamed(client C, name string)

AddNamed appends a client to the pool under the provider name `name`, which is reported in errors and logs when this client is used and fails.

func (*Clients[C]) Names added in v1.17.0

func (c *Clients[C]) Names() []string

Names returns the provider names of all clients in the pool, in pool order (which changes when the pool is sorted, see Clients.StartSorting).

func (*Clients[C]) Reset added in v1.17.0

func (c *Clients[C]) Reset()

Reset brings the rolling strategy back to the pool's declared order, so that the next call to WithClients/WithClientsContext starts again from the first client of the pool. It's the failback operation: a sticky strategy that rolled to a fallback provider after a transient error would otherwise stay on that fallback until the process restarts.

func (*Clients[C]) StartSorting added in v1.6.8

func (c *Clients[C]) StartSorting(ctx context.Context, direction SortDirection, sortValueFetcher SortValueFetcher[C], every time.Duration)

type RollingStrategy added in v1.6.8

type RollingStrategy[C any] interface {
	// contains filtered or unexported methods
}

type RollingStrategyAlwaysUseFirst deprecated added in v1.6.8

type RollingStrategyAlwaysUseFirst[C any] = RollingStrategySequential[C]

RollingStrategyAlwaysUseFirst is a deprecated alias, use RollingStrategySequential instead.

Deprecated: use RollingStrategySequential via NewRollingStrategySequential instead.

func NewRollingStrategyAlwaysUseFirst deprecated added in v1.6.8

func NewRollingStrategyAlwaysUseFirst[C any]() *RollingStrategyAlwaysUseFirst[C]

NewRollingStrategyAlwaysUseFirst returns a RollingStrategySequential with no options, matching this constructor's original (pre-WithSpreadStart) behavior: every call starts at the pool's first client.

Deprecated: use NewRollingStrategySequential instead.

type RollingStrategySequential added in v1.20.0

type RollingStrategySequential[C any] struct {
	// contains filtered or unexported fields
}

RollingStrategySequential walks the pool in order (declared, or last sorted) starting from a configurable client, rolling forward through the rest of the pool for failover. Without options it always starts at the pool's first client; see WithSpreadStart to spread the starting client across calls instead.

func NewRollingStrategySequential added in v1.20.0

func NewRollingStrategySequential[C any](opts ...RollingStrategySequentialOption) *RollingStrategySequential[C]

type RollingStrategySequentialOption added in v1.20.0

type RollingStrategySequentialOption func(*rollingStrategySequentialOptions)

RollingStrategySequentialOption configures NewRollingStrategySequential.

func WithSpreadStart added in v1.20.0

func WithSpreadStart() RollingStrategySequentialOption

WithSpreadStart makes the strategy spread its *starting* client round-robin across successive WithClientsContext calls instead of always starting at the pool's first client, while preserving the pool's declared (or last sorted) order for failover once a call has picked its start. It's for pools used by batched/parallel polling, where concurrent calls would otherwise all start on the same provider — unlike StickyRollingStrategy, a call never stays on the provider a previous call ended up rolling to, so this should not be used where staying on a known-good provider matters more than spreading load.

type SortDirection added in v1.6.8

type SortDirection int
const (
	SortDirectionAscending SortDirection = iota
	SortDirectionDescending
)

type SortValueFetcher added in v1.6.8

type SortValueFetcher[C any] interface {
	FetchSortValue(ctx context.Context, client C) (sortValue uint64, err error)
}

type StickyRollingStrategy added in v1.6.8

type StickyRollingStrategy[C any] struct {
	// contains filtered or unexported fields
}

func NewStickyRollingStrategy added in v1.6.8

func NewStickyRollingStrategy[C any]() *StickyRollingStrategy[C]

Jump to

Keyboard shortcuts

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