0PricingLogin
Go Academy · Lesson

Pipeline and Stage Patterns

Composing multi-stage concurrent pipelines

What is a pipeline?

A concurrent pipeline is a series of stages connected by channels. Each stage receives values from upstream, transforms them, and sends results downstream, allowing stages to run concurrently.

Simple three-stage pipeline

Generate → transform → consume:

func generate(nums ...int) <-chan int {
    out := make(chan int)
    go func() { defer close(out); for _, n := range nums { out <- n } }()
    return out
}
func square(in <-chan int) <-chan int {
    out := make(chan int)
    go func() { defer close(out); for n := range in { out <- n*n } }()
    return out
}

for v := range square(generate(2, 3, 4)) {
    fmt.Println(v) // 4, 9, 16
}

All lessons in this course

  1. Pipeline and Stage Patterns
  2. errgroup for Concurrent Error Handling
  3. Semaphore Pattern
  4. Leak Detection and Cancellation
← Back to Go Academy