-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcontext.go
55 lines (45 loc) · 860 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package consul
import (
"context"
"time"
)
func errorContext(ctx context.Context, err error) (context.Context, context.CancelFunc) {
return newErrorCtx(ctx, err), func() {}
}
func coalesceError(errs ...error) error {
for _, err := range errs {
if err != nil {
return err
}
}
return nil
}
type contextKey struct {
name string
}
type errorCtx struct {
ctx context.Context
err error
done chan struct{}
}
func newErrorCtx(ctx context.Context, err error) *errorCtx {
done := make(chan struct{})
close(done)
return &errorCtx{
ctx: ctx,
err: err,
done: done,
}
}
func (*errorCtx) Deadline() (deadline time.Time, ok bool) {
return
}
func (e *errorCtx) Done() <-chan struct{} {
return e.done
}
func (e *errorCtx) Err() error {
return e.err
}
func (e *errorCtx) Value(key interface{}) interface{} {
return e.ctx.Value(key)
}