Golang Context
2021-02-03 18:09:18 0 举报
有这幅图相信学习 context 源码的你可以更好的理解
作者其他创作
大纲/内容
timer *time.Timer
// newCancelCtx returns an initialized cancelCtx.
newCancelCtx(parent Context) cancelCtx
cancelCtx
bCtx
Done() <-chan struct{}
mu sync.Mutex
如果当前 deline 比新的早
childer map[canceler]struct{}
done chan struct{}
String() string
// propagateCancel arranges for child to be canceled when parent is.
timerCtx
valueCtx
Background() Context
// removeChild removes a context from its parent.
Context
deadline time.Time
removeFromParent == true
Value(key interface{}) interface{}
parent
func newCancelCtx(parent Context) cancelCtx { return cancelCtx{Context: parent}}
err error
var ( background = new(emptyCtx) todo = new(emptyCtx))
// parentCancelCtx follows a chain of parent references until it finds a// *cancelCtx. This function understands how each of the concrete types in this// package represents its parent.
TODO() Context
???
Err() error
emptyCtx
func (c *timerCtx) String() string { return contextName(c.cancelCtx.Context) + \".WithDeadline(\" + c.deadline.String() + \" [\" + time.Until(c.deadline).String() + \"])\"}
func (c *valueCtx) Value(key interface{}) interface{} { if c.key == key { return c.val } return c.Context.Value(key)}
func (c *valueCtx) String() string { return contextName(c.Context) + \".WithValue(type \" + reflectlite.TypeOf(c.key).String() + \
收藏
0 条评论
下一页