1// Copyright 2019 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5// Package xcontext is a package to offer the extra functionality we need 6// from contexts that is not available from the standard context package. 7package xcontext 8 9import ( 10 "context" 11 "time" 12) 13 14// Detach returns a context that keeps all the values of its parent context 15// but detaches from the cancellation and error handling. 16func Detach(ctx context.Context) context.Context { return detachedContext{ctx} } 17 18type detachedContext struct{ parent context.Context } 19 20func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false } 21func (v detachedContext) Done() <-chan struct{} { return nil } 22func (v detachedContext) Err() error { return nil } 23func (v detachedContext) Value(key interface{}) interface{} { return v.parent.Value(key) } 24