if parent == nil {
panic("cannot create context from nil parent")
}
- c := newCancelCtx(parent)
+ c := &cancelCtx{Context: parent}
propagateCancel(parent, c)
return c
}
return nil
}
-// newCancelCtx returns an initialized cancelCtx.
-func newCancelCtx(parent Context) *cancelCtx {
- return &cancelCtx{Context: parent}
-}
-
// goroutines counts the number of goroutines ever created; for testing.
var goroutines atomic.Int32
return WithCancel(parent)
}
c := &timerCtx{
- cancelCtx: newCancelCtx(parent),
+ cancelCtx: cancelCtx{Context: parent},
deadline: d,
}
propagateCancel(parent, c)
// implement Done and Err. It implements cancel by stopping its timer then
// delegating to cancelCtx.cancel.
type timerCtx struct {
- *cancelCtx
+ cancelCtx
timer *time.Timer // Under cancelCtx.mu.
deadline time.Time
c = ctx.Context
case *timerCtx:
if key == &cancelCtxKey {
- return ctx.cancelCtx
+ return &ctx.cancelCtx
}
c = ctx.Context
case *emptyCtx: