代码
```go
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 400*time.Millisecond)
defer cancel()
go handle(ctx, 1500*time.Millisecond)
fmt.Println("ab........")
select {
case <-ctx.Done():
fmt.Println("main", ctx.Err())
}
}
func handle(ctx context.Context, duration time.Duration) {
fmt.Println("a......")
select {
case <-ctx.Done():
fmt.Println("handle", ctx.Err())
case <-time.After(duration):
fmt.Println("process request with", duration)
}
}
```
测试的结果是
```go
1
main context deadline exceeded
2
main context deadline exceeded
handle context deadline exceeded
3
handle context deadline exceeded
main context deadline exceeded
```
请教, 什么原因导致的这3种结果?涉及到哪些知识点?
有疑问加站长微信联系(非本文作者)