Category: Go

【Go】Context用法

Context 主要被用于在并发的 goroutine 之间传递请求范围的数据、取消信号以及超时信息等。其中包含4个方法 Done() <-chan strct{}:当 Context 被取消或超时时,这个通道会被关闭。通常用于在 goroutine 中监听取消信号 Err() error:表示为什么 Context 被取消。当 Done() 通道关闭后调用 Err() 方法会返回非 ni