forked from taggledevel2/ratchet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_stage.go
50 lines (46 loc) · 1.5 KB
/
pipeline_stage.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
package ratchet
// PipelineStage holds one or more DataProcessor instances.
type PipelineStage struct {
processors []*dataProcessor
}
// NewPipelineStage creates a PipelineStage instance given a series
// of dataProcessors. dataProcessor (lower-case d) is a private wrapper around
// an object implementing the public DataProcessor interface. The
// syntax used to create PipelineLayouts abstracts this type
// away from your implementing code. For example:
//
// layout, err := ratchet.NewPipelineLayout(
// ratchet.NewPipelineStage(
// ratchet.Do(aDataProcessor).Outputs(anotherDataProcessor),
// // ...
// ),
// // ...
// )
//
// Notice how the ratchet.Do() and Outputs() functions allow you to insert
// DataProcessor instances into your PipelineStages without having to
// worry about the internal dataProcessor type or how any of the
// channel management works behind the scenes.
//
// See the ratchet package documentation for more code examples.
func NewPipelineStage(processors ...*dataProcessor) *PipelineStage {
return &PipelineStage{processors}
}
func (s *PipelineStage) hasProcessor(p DataProcessor) bool {
for i := range s.processors {
if s.processors[i].DataProcessor == p {
return true
}
}
return false
}
func (s *PipelineStage) hasOutput(p DataProcessor) bool {
for i := range s.processors {
for j := range s.processors[i].outputs {
if s.processors[i].outputs[j] == p {
return true
}
}
}
return false
}