Fan-Out Fan-In
Distribute and collect work.
Fan-Out and Fan-In
Fan-out means starting several goroutines to read from one channel, distributing work. Fan-in means merging the outputs of several goroutines back into one channel.
- Fan-out spreads load across workers
- Fan-in consolidates results for the consumer
A Generator Stage
The pipeline starts with a generator: a function that returns a channel and feeds values into it from its own goroutine, then closes it.
func gen(nums ...int) <-chan int {
out := make(chan int)
go func() {
for _, n := range nums {
out <- n
}
close(out)
}()
return out
}All lessons in this course
- Worker Pool Pattern
- Fan-Out Fan-In
- Pipeline Stages
- Graceful Shutdown