Documentation ¶
Index ¶
- Variables
- func CallCancel(ctx context.Context) error
- func CarryCancel(ctx context.Context, cancelFunc context.CancelFunc) context.Context
- func Done(ctx context.Context) bool
- func PutVal[T any](ctx context.Context, key *Value[T], v T)
- func WaitCtx(ctx context.Context) (dctx context.Context, done func())
- func WithWait(sctx context.Context, planNum int32, to ...time.Duration) (dctx context.Context, done func() error)
- type Ctx
- type Value
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 CarryCancel ¶
func WaitCtx ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.