ctx

package
v0.28.20240101151147 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: MIT Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWaitTo      = errors.New("ErrWaitTo")
	ErrNothingWait = errors.New("ErrNothingWait")
)
View Source
var (
	ErrNotCarryYet = errors.New("ErrNotCarryYet")
)

Functions

func CallCancel

func CallCancel(ctx context.Context) error

func CarryCancel

func CarryCancel(ctx context.Context, cancelFunc context.CancelFunc) context.Context

func Done

func Done(ctx context.Context) bool

func PutVal

func PutVal[T any](ctx context.Context, key *Value[T], v T)

func WaitCtx

func WaitCtx(ctx context.Context) (dctx context.Context, done func())
go func(){
	ctx1, done1 := WaitCtx(mainCtx)
	defer done1()
	do something..
	<-ctx1.Done() // wait mainDone call
}()

func WithWait

func WithWait(sctx context.Context, planNum int32, to ...time.Duration) (dctx context.Context, done func() error)

planNum 可以为0 表示无法预知的调用次数,如果在mainDone调用前没有Wait、WithWait时,mainDone将返回ErrNothingWait

	mainCtx, mainDone := WithWait(ctx, 0, time.Second)
	defer mainDone()// wait done1 or after one second

	go func(){
		ctx1, done1 := WaitCtx(mainCtx)
		defer done1()
		do something..
 		<-ctx1.Done() // wait mainDone call
	}()

Types

type Ctx

type Ctx struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

errCtx := pctx.Value[error]{}

cancelC = errCtx.LinkCtx(cancelC)

pctx.PutVal(cancelC, &errCtx, fmt.Errorf("%vs未接收到有效数据", readTO))

err := errCtx.Get()

func (*Value[T]) Get

func (t *Value[T]) Get() T

func (*Value[T]) LinkCtx

func (t *Value[T]) LinkCtx(ctx context.Context) context.Context

func (*Value[T]) Set

func (t *Value[T]) Set(data T)

Jump to

Keyboard shortcuts

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