-
Notifications
You must be signed in to change notification settings - Fork 85
/
context.go
35 lines (27 loc) · 873 Bytes
/
context.go
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
27
28
29
30
31
32
33
34
35
package util
import (
"context"
"time"
)
// NewDetachedContext produces a new context that has a separate cancellation mechanism from its parent. This should be
// used when having to continue using a context after it has been canceled, such as cleaning up Docker resources
// after the context has been canceled but want to keep work associated with the same trace.
func NewDetachedContext(parent context.Context) context.Context {
return detachedContext{parent: parent}
}
var _ context.Context = detachedContext{}
type detachedContext struct {
parent context.Context
}
func (d detachedContext) Deadline() (deadline time.Time, ok bool) {
return time.Time{}, false
}
func (d detachedContext) Done() <-chan struct{} {
return nil
}
func (d detachedContext) Err() error {
return nil
}
func (d detachedContext) Value(key any) any {
return d.parent.Value(key)
}