Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCancelReason ¶
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 ¶
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 ¶
WithCancel adds an info log to context.WithCancel's CancelFunc. Prefer using WithCancelReason when possible.
Types ¶
type CancelWithReasonFunc ¶
type CancelWithReasonFunc func(reason error)
CancelWithReasonFunc is a context.CancelFunc that also passes along an error that is the reason for cancellation.
func WithCancelReason ¶
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 ¶
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) Error ¶
func (t *TimeoutError) Error() string
func (*TimeoutError) Format ¶
func (t *TimeoutError) Format(s fmt.State, verb rune)
Format implements fmt.Formatter.
func (*TimeoutError) FormatError ¶
func (t *TimeoutError) FormatError(p errors.Printer) error
FormatError implements errors.Formatter.
func (*TimeoutError) Temporary ¶
func (*TimeoutError) Temporary() bool
Temporary implements net.Error.