forked from buptmiao/parallel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline.go
More file actions
32 lines (27 loc) · 685 Bytes
/
pipeline.go
File metadata and controls
32 lines (27 loc) · 685 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
package parallel
// Pipeline instance, which executes jobs by serial
type Pipeline struct {
handlers []*Handler
}
// NewPipeline creates a new Pipeline instance
func NewPipeline() *Pipeline {
res := new(Pipeline)
return res
}
// Register add a new function to pipeline
func (p *Pipeline) Register(f interface{}, args ...interface{}) *Handler {
h := NewHandler(f, args...)
p.Add(h)
return h
}
// Add add new handlers to pipeline
func (p *Pipeline) Add(hs ...*Handler) *Pipeline {
p.handlers = append(p.handlers, hs...)
return p
}
// Do calls all handlers as the sequence they are added into pipeline.
func (p *Pipeline) Do() {
for _, h := range p.handlers {
h.Do()
}
}