-
Notifications
You must be signed in to change notification settings - Fork 159
/
std.go
72 lines (58 loc) · 1.22 KB
/
std.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
package extension
import (
"fmt"
"github.com/reugn/go-streams"
)
// StdoutSink represents a simple outbound connector that writes
// streaming data to standard output.
type StdoutSink struct {
in chan any
}
var _ streams.Sink = (*StdoutSink)(nil)
// NewStdoutSink returns a new StdoutSink connector.
func NewStdoutSink() *StdoutSink {
sink := &StdoutSink{
in: make(chan any),
}
sink.init()
return sink
}
func (stdout *StdoutSink) init() {
go func() {
for elem := range stdout.in {
fmt.Println(elem)
}
}()
}
// In returns the input channel of the StdoutSink connector.
func (stdout *StdoutSink) In() chan<- any {
return stdout.in
}
// IgnoreSink represents a simple outbound connector that discards
// all elements of a stream.
type IgnoreSink struct {
in chan any
}
var _ streams.Sink = (*IgnoreSink)(nil)
// NewIgnoreSink returns a new IgnoreSink connector.
func NewIgnoreSink() *IgnoreSink {
sink := &IgnoreSink{
in: make(chan any),
}
sink.init()
return sink
}
func (ignore *IgnoreSink) init() {
go func() {
for {
_, ok := <-ignore.in
if !ok {
break
}
}
}()
}
// In returns the input channel of the IgnoreSink connector.
func (ignore *IgnoreSink) In() chan<- any {
return ignore.in
}