浅谈GO-context

type Context interface {

    Deadline() (deadline time.Time, ok bool)

    Done() <-chan struct{}

    Err() error

    Value(key interface{}) interface{}

}

 

context顾名思义为上下文,主要用于多个树形结构gorutine之间,常用功能有超时设置(deadline)、链路追踪(value里面写入tracelogId)、父子协程通信(父协程cancel 子协程可在Done channel中收到信号)

posted @ 2022-03-08 14:46  hugeQAQ  阅读(34)  评论(0)    收藏  举报