From 90b560cd759e648215593e1833f1c4818b70e591 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Tue, 22 Jun 2021 12:42:20 +0100 Subject: [PATCH] use value delegate to separate value and cancel This is a issue with the usage of context for value storage and cancell signaling. This issue will be addressed in a permanent way in v5. --- context.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 39c1dc045..89516d1f7 100644 --- a/context.go +++ b/context.go @@ -49,6 +49,14 @@ func toContext(ctx context.Context, v *Instance) context.Context { Internal API */ func ToBackgroundDetachedContext(ctx context.Context) context.Context { - instance := MustFromContext(ctx) - return toContext(context.Background(), instance) + return &temporaryValueDelegationFix{context.Background(), ctx} +} + +type temporaryValueDelegationFix struct { + context.Context + value context.Context +} + +func (t *temporaryValueDelegationFix) Value(key interface{}) interface{} { + return t.value.Value(key) }