Pipeline Stages
Chain channel stages.
What Is a Pipeline
A pipeline is a series of stages connected by channels. Each stage receives values, does work, and sends results downstream. Data flows like an assembly line.
- Each stage is a goroutine
- Stages communicate only through channels
- Composable and easy to reason about
Stage Signature Convention
By convention each stage takes one or more receive-only input channels and returns a receive-only output channel. This makes stages chainable.
func stage(in <-chan int) <-chan int {
out := make(chan int)
go func() {
defer close(out)
for v := range in {
out <- v
}
}()
return out
}All lessons in this course
- Worker Pool Pattern
- Fan-Out Fan-In
- Pipeline Stages
- Graceful Shutdown