-
Notifications
You must be signed in to change notification settings - Fork 1
/
output.go
56 lines (47 loc) · 974 Bytes
/
output.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
package modules
import (
"sync"
)
// Output -
type Output struct {
connectedInputs []*Input
name string
mx sync.RWMutex
}
// NewOutput -
func NewOutput(name string) *Output {
return &Output{
connectedInputs: make([]*Input, 0),
name: name,
}
}
// ConnectedInputs -
func (output *Output) ConnectedInputs() []*Input {
return output.connectedInputs
}
// Push -
func (output *Output) Push(msg any) {
output.mx.RLock()
{
for i := range output.connectedInputs {
output.connectedInputs[i].Push(msg)
}
}
output.mx.RUnlock()
}
// Attach -
func (output *Output) Attach(input *Input) {
output.mx.Lock()
{
output.connectedInputs = append(output.connectedInputs, input)
}
output.mx.Unlock()
}
// Name -
func (output *Output) Name() string {
return output.name
}
// Connect -
func Connect(outputModule, inputModule Module, outputName, inputName string) error {
return inputModule.AttachTo(outputModule, outputName, inputName)
}