-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput.go
More file actions
51 lines (43 loc) · 722 Bytes
/
input.go
File metadata and controls
51 lines (43 loc) · 722 Bytes
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
package modules
const (
defaultCapacity = 1024
)
// Input -
type Input struct {
data chan any
name string
}
// NewInput -
func NewInput(name string) *Input {
return &Input{
data: make(chan any, defaultCapacity),
name: name,
}
}
// NewInputWithCapacity -
func NewInputWithCapacity(name string, cap int) *Input {
if cap < 0 {
cap = defaultCapacity
}
return &Input{
data: make(chan any, cap),
name: name,
}
}
// Close -
func (input *Input) Close() error {
close(input.data)
return nil
}
// Push -
func (input *Input) Push(msg any) {
input.data <- msg
}
// Listen -
func (input *Input) Listen() <-chan any {
return input.data
}
// Name -
func (input *Input) Name() string {
return input.name
}