Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 1012 Bytes

File metadata and controls

28 lines (21 loc) · 1012 Bytes

appctx

CI GoDoc GitHub release GitHub

Examples

Global

// canceled this context when received os signals for termination
ctx := appctx.Global()

inspired by github.com/moby/buildkit/util/appcontext

Clone

baseCtx, cancel := context.WithCancel(context.Background())
baseCtx = context.WithValue(baseCtx, "user_id", 123)

newCtx := appctx.Clone(baseCtx)
cancel()

fmt.Println(newCtx.Value("user_id"), baseCtx.Value("user_id")) // => 123 123
fmt.Println(newCtx.Err(), baseCtx.Err()) // => <nil> context canceled