Golang Context 探究
。源码中有两个类型实现了 canceler 接口:*cancelCtx 和 *timerCtx 1 2 3 4 type canceler interface { cancel(removeFromParent bool, err error) Done() <-chan struct{} } context.cancelCtx 首先函数 WithCancel 就是我们用来创建可以取消的 context(context.cancelCtx) 的入口。 1 2 3 4 5 6 7 func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { // 将传入的上下文包装成私有结构体 context.cancelCtx c...阅读全文