contextx

package
v0.0.0-...-d3b5644 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextType = reflect.TypeOf((*context.Context)(nil)).Elem()

Functions

func Error

func Error(ctx context.Context) error

func ShrinkDeadline

func ShrinkDeadline(ctx context.Context, dur time.Duration) time.Time

ShrinkDeadline calculates a new deadline based on the given duration `dur` and context `ctx`. If no deadline is set in `ctx`, it returns the current time plus `dur`. If a deadline is set in `ctx`, it returns the earlier of the two deadlines.

func Signal

func Signal(signals ...os.Signal) (context.Context, context.CancelFunc)

Signal creates a new context that cancels on the given signals.

func SignalCause

func SignalCause(signals ...os.Signal) (context.Context, context.CancelCauseFunc)

SignalCause creates a new context that cancels on the given signals.

func WithSignal

func WithSignal(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelFunc)

WithSignal like signal.NotifyContext.

func WithSignalCause

func WithSignalCause(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelCauseFunc)

func WithoutCancel

func WithoutCancel(parent context.Context) context.Context

WithoutCancel returns a copy of parent that is not canceled when parent is canceled. The returned context returns no Deadline or Err, and its Done channel is nil. Calling [Cause] on the returned context returns nil. copy from go1.21 "context"

Types

type SignalError

type SignalError struct {
	Signal os.Signal
}

func (SignalError) Error

func (e SignalError) Error() string

Jump to

Keyboard shortcuts

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