func tctx() {
f := func() context.Context {
ctx := context.TODO()
ctx = context.WithValue(ctx, “k”, “v”)
myprint(ctx.Value(“k”))
return ctx
ctx := f()
ctx, _ = context.WithTimeout(ctx, 32*time.Second)
myprint(“2”, ctx.Value(“k”))
func myprint(l …interface{}) {
fmt.Println(l…)
Original: https://www.cnblogs.com/rsapaper/p/16525896.html
Author: rsapaper_ing
Title: context.WithValue context.WithTimeout
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/545768/
转载文章受原作者版权保护。转载请注明原作者出处!