forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
39 lines (31 loc) · 1.01 KB
/
context.go
File metadata and controls
39 lines (31 loc) · 1.01 KB
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
36
37
38
39
package diskcache
import (
"context"
"time"
)
type isolatedTimeoutContext struct {
parent context.Context
deadlineCtx context.Context
}
// withIsolatedTimeout creates a context with a timeout isolated from any timeouts in any of the ancestor contexts.
// Context values are pulled from the parent context only.
func withIsolatedTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
deadlineCtx, cancelFunc := context.WithTimeout(context.Background(), timeout)
return &isolatedTimeoutContext{
parent: parent,
deadlineCtx: deadlineCtx,
}, cancelFunc
}
var _ context.Context = &isolatedTimeoutContext{}
func (c *isolatedTimeoutContext) Deadline() (time.Time, bool) {
return c.deadlineCtx.Deadline()
}
func (c *isolatedTimeoutContext) Done() <-chan struct{} {
return c.deadlineCtx.Done()
}
func (c *isolatedTimeoutContext) Err() error {
return c.deadlineCtx.Err()
}
func (c *isolatedTimeoutContext) Value(key interface{}) interface{} {
return c.parent.Value(key)
}