package main
import (
"context"
"fmt"
"time"
)
func main() {
ctx, cancelFunc := context.WithDeadline(context.Background(), time.Now().Add(time.Second*10))
t, ok := ctx.Deadline()
if ok {
fmt.Println(time.Now())
fmt.Println(t.String())
}
go func(ctx context.Context) {
fmt.Println(ctx.Value("Test"))
<-ctx.Done()
fmt.Println(ctx.Err())
}(ctx)
if ctx.Err() == nil {
time.Sleep(11e9)
}
if ctx.Err() != nil {
fmt.Println("已经退出了")
}
cancelFunc()
}