-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.go
39 lines (30 loc) · 821 Bytes
/
tree.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
package byo_context
type children map[Context]struct{}
func (ch *children) addChild(ctx Context) {
if *ch == nil {
*ch = make(map[Context]struct{})
}
(*ch)[ctx] = struct{}{}
}
func (ch *children) removeChild(ctx Context) {
if *ch == nil {
panic("children: removeChild called on nil children")
}
delete(*ch, ctx)
}
func (ch *children) removeAll() {
*ch = nil
}
type treeOps interface {
addChild(ctx Context)
removeChild(ctx Context)
removeAll()
}
// assert that background implements the treeOps interface
var _ treeOps = &background{}
// assert that cancelCtx implements the treeOps interface
var _ treeOps = &cancelCtx{}
// assert that valueCtx implements the treeOps interface
var _ treeOps = &valueCtx{}
// assert that deadlineCtx implements the treeOps interface
var _ treeOps = &deadlineCtx{}