-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_synchronized.go
107 lines (78 loc) · 2.14 KB
/
process_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
107
package jasper
import (
"context"
"sync"
"syscall"
)
type synchronizedProcess struct {
proc Process
mutex sync.RWMutex
}
func SyncrhonizeProcess(proc Process) Process { return &synchronizedProcess{proc: proc} }
func (p *synchronizedProcess) ID() string {
p.mutex.RLock()
defer p.mutex.RUnlock()
return p.proc.ID()
}
func (p *synchronizedProcess) Info(ctx context.Context) ProcessInfo {
p.mutex.RLock()
defer p.mutex.RUnlock()
return p.proc.Info(ctx)
}
func (p *synchronizedProcess) Running(ctx context.Context) bool {
p.mutex.RLock()
defer p.mutex.RUnlock()
return p.proc.Running(ctx)
}
func (p *synchronizedProcess) Complete(ctx context.Context) bool {
p.mutex.RLock()
defer p.mutex.RUnlock()
return p.proc.Complete(ctx)
}
func (p *synchronizedProcess) Signal(ctx context.Context, sig syscall.Signal) error {
p.mutex.Lock()
defer p.mutex.Unlock()
return p.proc.Signal(ctx, sig)
}
func (p *synchronizedProcess) Tag(t string) {
p.mutex.Lock()
defer p.mutex.Unlock()
p.proc.Tag(t)
}
func (p *synchronizedProcess) ResetTags() {
p.mutex.Lock()
defer p.mutex.Unlock()
p.proc.ResetTags()
}
func (p *synchronizedProcess) GetTags() []string {
p.mutex.RLock()
defer p.mutex.RUnlock()
return p.proc.GetTags()
}
func (p *synchronizedProcess) RegisterTrigger(ctx context.Context, trigger ProcessTrigger) error {
p.mutex.Lock()
defer p.mutex.Unlock()
return p.proc.RegisterTrigger(ctx, trigger)
}
func (p *synchronizedProcess) RegisterSignalTrigger(ctx context.Context, trigger SignalTrigger) error {
p.mutex.Lock()
defer p.mutex.Unlock()
return p.proc.RegisterSignalTrigger(ctx, trigger)
}
func (p *synchronizedProcess) RegisterSignalTriggerID(ctx context.Context, trigger SignalTriggerID) error {
p.mutex.Lock()
defer p.mutex.Unlock()
return p.proc.RegisterSignalTriggerID(ctx, trigger)
}
func (p *synchronizedProcess) Wait(ctx context.Context) (int, error) {
p.mutex.Lock()
defer p.mutex.Unlock()
exitCode, err := p.proc.Wait(ctx)
return exitCode, err
}
func (p *synchronizedProcess) Respawn(ctx context.Context) (Process, error) {
p.mutex.Lock()
defer p.mutex.Unlock()
newProc, err := p.proc.Respawn(ctx)
return newProc, err
}