type Context interface{Deadline()(deadline time.Time, ok bool)//返回截止时间Done()<-chanstruct{}// 当前任务被取消时,返回一个关闭的channel,否则返回nilErr()errorValue(key interface{})interface{}// 返回context存储的键值对中当前key对应的值}
type cancelCtx struct{
Context
mu sync.Mutex // protects following fields
done chanstruct{}// created lazily, closed by first cancel call
children map[canceler]struct{}// set to nil by the first cancel call
err error// set to non-nil by the first cancel call}
timerCtx 基于cancelctx的类型,可以定时取消
type timerCtx struct{
cancelCtx
timer *time.Timer // Under cancelCtx.mu.
deadline time.Time
}