MCPcopy
hub / github.com/kubernetes/kubernetes / WithCancel

Method WithCancel

test/utils/ktesting/withcontext.go:29–41  ·  view source on GitHub ↗

WithCancel sets up cancellation in a [TContext.Cleanup] callback and constructs a new TContext where [TContext.Cancel] cancels only the new context.

()

Source from the content-addressed store, hash-verified

27// constructs a new TContext where [TContext.Cancel] cancels only the new
28// context.
29func (tCtx TContext) WithCancel() TContext {
30 ctx, cancel := context.WithCancelCause(tCtx)
31
32 tCtx.Context = ctx
33 tCtx.cancel = func(cause string) {
34 var cancelCause error
35 if cause != "" {
36 cancelCause = canceledError(cause)
37 }
38 cancel(cancelCause)
39 }
40 return tCtx
41}
42
43// WithoutCancel causes the returned context to ignore cancellation of its parent.
44// Calling Cancel will only cancel the new context.

Calls 1

canceledErrorTypeAlias · 0.85