contextx

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValue

func GetValue[V any](ctx context.Context, k Key[V]) option.Option[V]

GetValue returns the value associated with this context for key, wrapped in a Optinal; or empty Option if no value is associated with key.

func New

func New() context.Context

New create new Context

func NewWithCancel

func NewWithCancel() (ctx context.Context, cancel context.CancelFunc)

NewWithCancel create new Context can be canceled

func NewWithDeadline

func NewWithDeadline(deadline time.Time) (ctx context.Context, cancel context.CancelFunc)

NewWithDeadline create new Context with a deadline

func NewWithTimeout

func NewWithTimeout(timeout time.Duration) (ctx context.Context, cancel context.CancelFunc)

NewWithTimeout create new Context with a timeout value

func WithValue

func WithValue[V any](ctx context.Context, k Key[V], value V) context.Context

WithValue returns a copy of parent Context in which the value associated with key is value.

Types

type Key

type Key[V any] struct {
	// contains filtered or unexported fields
}

Key is for strong type Context value store/get. V is the context value type

func NewKey

func NewKey[V any](key any) Key[V]

NewKey create new key

func (Key[V]) Key

func (k Key[V]) Key() any

Key return the key value

Jump to

Keyboard shortcuts

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