MCPcopy Create free account
hub / github.com/devspace-sh/devspace / WithContext

Function WithContext

pkg/util/tomb/context.go:11–27  ·  view source on GitHub ↗

WithContext returns a new tomb that is killed when the provided parent context is canceled, and a copy of parent with a replaced Done channel that is closed when either the tomb is dying or the parent is canceled. The returned context may also be obtained via the tomb's Context method.

(parent context.Context)

Source from the content-addressed store, hash-verified

9// that is closed when either the tomb is dying or the parent is canceled.
10// The returned context may also be obtained via the tomb's Context method.
11func WithContext(parent context.Context) (*Tomb, context.Context) {
12 var t Tomb
13 t.init()
14 if parent.Done() != nil {
15 go func() {
16 select {
17 case <-t.Dying():
18 case <-parent.Done():
19 t.Kill(parent.Err())
20 }
21 }()
22 }
23 t.parent = parent
24 child, cancel := context.WithCancel(parent)
25 t.addChild(parent, child, cancel)
26 return &t, child
27}
28
29// Context returns a context that is a copy of the provided parent context with
30// a replaced Done channel that is closed when either the tomb is dying or the

Callers 2

WithNewTombMethod · 0.92
startCommandMethod · 0.92

Calls 6

initMethod · 0.95
DyingMethod · 0.95
KillMethod · 0.95
addChildMethod · 0.95
DoneMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected