浏览代码

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.
Shelikhoo 4 年之前
父节点
当前提交
90b560cd75
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      context.go

+ 10 - 2
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)
 }