-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext.go
45 lines (37 loc) · 824 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
package graphblas
import (
"context"
)
// Mode for blocking
type Mode = int
const (
// Blocking until each method has completed
Blocking Mode = iota
// NonBlocking may execute methods in any order
NonBlocking
)
// Context exends the standard context to include Mode
type Context interface {
context.Context
Mode() Mode
}
// graphContect context with Mode support
type graphContect struct {
context.Context
mode Mode
}
// NewContext returns a Context
func NewContext(ctx context.Context, mode Mode) context.Context {
return &graphContect{ctx, mode}
}
func (s *graphContect) Mode() Mode {
return s.mode
}
// BlockingMode returns the Mode from the context
func BlockingMode(ctx context.Context) (Mode, bool) {
graph, ok := ctx.(*graphContect)
if ok {
return graph.Mode(), ok
}
return Blocking, false
}