gocloud.devgocloud.dev/internal/retry Index | Files

package retry

import "gocloud.dev/internal/retry"

Package retry provides retry logic.

Index

Functions

func Call

func Call(ctx context.Context, bo gax.Backoff, isRetryable func(error) bool, f func() error) error

Call calls the supplied function f repeatedly, using the isRetryable function and the provided backoff parameters to control the repetition.

When f returns nil, Call immediately returns nil.

When f returns an error for which isRetryable returns false, Call immediately returns that error.

When f returns an error for which isRetryable returns true, Call sleeps for the provided backoff value and invokes f again.

When the provided context is done, Retry returns a ContextError that includes both ctx.Error() and the last error returned by f, or nil if there isn't one.

Types

type ContextError

type ContextError struct {
	CtxErr  error // The error obtained from ctx.Err()
	FuncErr error // The error obtained from the function being retried, or nil
}

A ContextError contains both a context error (either context.Canceled or context.DeadlineExceeded), and the last error from the function being retried, or nil if the function was never called.

func (*ContextError) Error

func (e *ContextError) Error() string

func (*ContextError) Is

func (e *ContextError) Is(target error) bool

Is returns true iff one of the two errors held in e is equal to target.

Source Files

retry.go

Version
v0.42.0 (latest)
Published
Jun 28, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
10 hours ago

Tools for package owners.