cockroach: github.com/cockroachdb/cockroach/pkg/util/contextutil Index | Files

package contextutil

import "github.com/cockroachdb/cockroach/pkg/util/contextutil"

Index

Package Files

context.go

func GetCancelReason Uses

func GetCancelReason(ctx context.Context) error

GetCancelReason retrieves the cancel reason for a context that has been created via WithCancelReason. The reason will be nil if the context was not created with WithCancelReason, or if the context has not been canceled yet. Otherwise, the reason will be the error that the context's CancelWithReasonFunc was invoked with.

func RunWithTimeout Uses

func RunWithTimeout(
    ctx context.Context, op string, timeout time.Duration, fn func(ctx context.Context) error,
) error

RunWithTimeout runs a function with a timeout, the same way you'd do with context.WithTimeout. It improves the opaque error messages returned by WithTimeout by augmenting them with the op string that is passed in.

func WithCancel Uses

func WithCancel(parent context.Context) (context.Context, context.CancelFunc)

WithCancel adds an info log to context.WithCancel's CancelFunc. Prefer using WithCancelReason when possible.

type CancelWithReasonFunc Uses

type CancelWithReasonFunc func(reason error)

CancelWithReasonFunc is a context.CancelFunc that also passes along an error that is the reason for cancellation.

func WithCancelReason Uses

func WithCancelReason(ctx context.Context) (context.Context, CancelWithReasonFunc)

WithCancelReason adds a CancelFunc to this context, returning a new cancellable context and a CancelWithReasonFunc, which is like context.CancelFunc, except it also takes a "reason" error. The context that is canceled with this CancelWithReasonFunc will immediately be updated to contain this "reason". The reason can be retrieved with GetCancelReason. This function doesn't change the deadline of a context if it already exists.

type TimeoutError Uses

type TimeoutError struct {
    // contains filtered or unexported fields
}

TimeoutError is a wrapped ContextDeadlineExceeded error. It indicates that an operation didn't complete within its designated timeout.

func (*TimeoutError) Cause Uses

func (t *TimeoutError) Cause() error

Cause implements Causer.

func (*TimeoutError) Error Uses

func (t *TimeoutError) Error() string

func (*TimeoutError) Format Uses

func (t *TimeoutError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter.

func (*TimeoutError) FormatError Uses

func (t *TimeoutError) FormatError(p errors.Printer) error

FormatError implements errors.Formatter.

func (*TimeoutError) Temporary Uses

func (*TimeoutError) Temporary() bool

Temporary implements net.Error.

func (*TimeoutError) Timeout Uses

func (*TimeoutError) Timeout() bool

Timeout implements net.Error.

Package contextutil imports 8 packages (graph) and is imported by 45 packages. Updated 2019-07-24. Refresh now. Tools for package owners.