-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
26 lines (21 loc) · 807 Bytes
/
context.go
File metadata and controls
26 lines (21 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2024 Outreach Corporation. All Rights Reserved.
// Description: This file contains context related functions and struct
package plumber
import "context"
// detachedContext is context detached form original one.
type detachedContext struct {
context.Context
valueSource context.Context
}
// Value returns a value from the original context
func (dc *detachedContext) Value(key interface{}) interface{} {
return dc.valueSource.Value(key)
}
// DetachCancellation detaches the cancellation this should be used only with ContextCloser.
// It returns a new cancel function to not get context leaked.
func DetachCancellation(ctx context.Context) (context.Context, context.CancelFunc) {
return context.WithCancel(&detachedContext{
Context: context.Background(),
valueSource: ctx,
})
}