context.WithValue context.WithTimeout

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/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球