0PricingLogin
Go Academy · Lesson

Fan-in and Fan-out Patterns

Merging multiple channels and distributing work

What is fan-out?

Fan-out distributes work from one channel across multiple goroutines, allowing parallel processing. Each worker receives from the same input channel.

Fan-out example

Spin up N workers all reading from a shared jobs channel:

func fanOut(jobs <-chan Job, n int) {
    for i := 0; i < n; i++ {
        go func() {
            for job := range jobs {
                process(job)
            }
        }()
    }
}

All lessons in this course

  1. The select Statement
  2. Timeouts and Tickers
  3. Fan-in and Fan-out Patterns
  4. Worker Pool Pattern
← Back to Go Academy