-
Notifications
You must be signed in to change notification settings - Fork 4
/
manager_container.go
68 lines (54 loc) · 1.3 KB
/
manager_container.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
56
57
58
59
60
61
62
63
64
65
66
67
68
package runnable
import "context"
func newManagerContainer(runnable Runnable) *managerContainer {
ctx, cancel := context.WithCancel(context.Background())
return &managerContainer{
runnable: runnable,
ctx: ctx,
shutdown: cancel,
}
}
type managerContainer struct {
runnable Runnable
users []*managerContainer
ctx context.Context
shutdown func()
err error
}
func (c *managerContainer) insertUser(container *managerContainer) {
for _, item := range c.users {
if item == container {
return
}
}
c.users = append(c.users, container)
}
func (c *managerContainer) name() string {
return findName(c.runnable)
}
func (c *managerContainer) launch(completed chan *managerContainer, dying chan *managerContainer) {
go func() {
c.err = Recover(c.runnable).Run(c.ctx)
completed <- c
dying <- c
}()
}
type managerContainerSet map[*managerContainer]bool
func newManagerContainerSet() managerContainerSet {
return managerContainerSet{}
}
func (s managerContainerSet) insert(c *managerContainer) {
s[c] = true
}
func (s managerContainerSet) contains(c *managerContainer) bool {
_, has := s[c]
return has
}
func (s managerContainerSet) containerHasRunningUsers(c *managerContainer) bool {
for _, user := range c.users {
if _, ok := s[user]; !ok {
return true
}
}
return false
}