rpcutil

package
v0.0.0-...-72e4f35 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package rpcutil provides common utility functions for interacting with RPC clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestWithRetries

func RequestWithRetries(ctx context.Context, f func() error, extraTransientCodes ...codes.Code) error

RequestWithRetries calls a function that makes an RPC request. If the function returns an RPC error (possibly wrapped) it will be retried as long as the error matches one of a known set of transient error codes, or one of the error codes listed in `extraTransientCodes`.

Generic network errors that are marked as "temporary" will also be retried.

TODO(olivernewman): Once we're on Go 1.18, use generics to have this function pass through the callback's return value, which will help simplify callsites:

RequestWithRetries[T any](Context, func() (T, error), ...codes.Code) (T, error)

func StatusFromError

func StatusFromError(err error) (*status.Status, bool)

StatusFromError returns the GRPC status of the underlying cause of the error if it unwraps to a GRPC error, along with a true boolean. It returns false if the underlying cause of the error is not a GRPC error.

TODO(olivernewman): This is only necessary because `status.FromError()` doesn't unwrap errors. Delete this and use `status.FromError()` directly if and when it learns how to unwrap errors.

Types

This section is empty.

Jump to

Keyboard shortcuts

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