-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsink.go
More file actions
41 lines (36 loc) · 888 Bytes
/
sink.go
File metadata and controls
41 lines (36 loc) · 888 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
package flowbase
// Sink is a simple component that just receives IPs on its In-port without
// doing anything with them. It is used to drive pipelines of processes
type Sink struct {
BaseProcess
}
// NewSink returns a new Sink component
func NewSink(net *Network, name string) *Sink {
p := &Sink{
BaseProcess: NewBaseProcess(net, name),
}
p.InitInPort(p, "sink_in")
return p
}
func (p *Sink) in() *InPort { return p.InPort("sink_in") }
// From connects an out-port to the sinks in-port
func (p *Sink) From(outPort *OutPort) {
p.in().From(outPort)
}
// Run runs the Sink process
func (p *Sink) Run() {
merged := make(chan int)
if p.in().Ready() {
go func() {
for ip := range p.in().Chan {
Debug.Printf("Got file in sink: %s\n", ip.ID())
}
merged <- 1
}()
}
if p.in().Ready() {
<-merged
}
close(merged)
Debug.Printf("Caught up everything in sink")
}