-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_synchronized.go
106 lines (81 loc) · 2.34 KB
/
manager_synchronized.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package jasper
import (
"context"
"sync"
"github.com/tychoish/jasper/options"
)
type synchronizedProcessManager struct {
mu sync.RWMutex
manager Manager
}
func (m *synchronizedProcessManager) ID() string {
return m.manager.ID()
}
func (m *synchronizedProcessManager) CreateProcess(ctx context.Context, opts *options.Create) (Process, error) {
m.mu.Lock()
defer m.mu.Unlock()
proc, err := m.manager.CreateProcess(ctx, opts)
if err != nil {
return nil, err
}
return &synchronizedProcess{proc: proc}, nil
}
func (m *synchronizedProcessManager) CreateCommand(_ context.Context) *Command {
m.mu.RLock()
defer m.mu.RUnlock()
return NewCommand().ProcConstructor(m.CreateProcess)
}
func (m *synchronizedProcessManager) Register(ctx context.Context, proc Process) error {
m.mu.Lock()
defer m.mu.Unlock()
return m.manager.Register(ctx, proc)
}
func (m *synchronizedProcessManager) List(ctx context.Context, f options.Filter) ([]Process, error) {
m.mu.RLock()
defer m.mu.RUnlock()
procs, err := m.manager.List(ctx, f)
var syncedProcs []Process
for _, proc := range procs {
syncedProcs = append(syncedProcs, &synchronizedProcess{proc: proc})
}
return syncedProcs, err
}
func (m *synchronizedProcessManager) Get(ctx context.Context, id string) (Process, error) {
m.mu.RLock()
defer m.mu.RUnlock()
proc, err := m.manager.Get(ctx, id)
if err != nil {
return nil, err
}
return &synchronizedProcess{proc: proc}, err
}
func (m *synchronizedProcessManager) Clear(ctx context.Context) {
m.mu.Lock()
defer m.mu.Unlock()
m.manager.Clear(ctx)
}
func (m *synchronizedProcessManager) Close(ctx context.Context) error {
m.mu.Lock()
defer m.mu.Unlock()
return m.manager.Close(ctx)
}
func (m *synchronizedProcessManager) Group(ctx context.Context, name string) ([]Process, error) {
m.mu.RLock()
defer m.mu.RUnlock()
procs, err := m.manager.Group(ctx, name)
var syncedProcs []Process
for _, proc := range procs {
syncedProcs = append(syncedProcs, &synchronizedProcess{proc: proc})
}
return syncedProcs, err
}
func (m *synchronizedProcessManager) LoggingCache(ctx context.Context) LoggingCache {
m.mu.RLock()
defer m.mu.RUnlock()
return m.manager.LoggingCache(ctx)
}
func (m *synchronizedProcessManager) WriteFile(ctx context.Context, opts options.WriteFile) error {
m.mu.Lock()
defer m.mu.Unlock()
return m.manager.WriteFile(ctx, opts)
}