The prime number pipeline algorithm generates primes by sending candidate integers through a chain of goroutines. Each stage represents a discovered prime and filters out its multiples; survivors continue to the next stage. section 9.2.7
A dynamic Go pipeline proceeds as follows:
- Create a new goroutine and channel when a surviving value reaches the chain's end. section 9.2.7
Generating primes below 100,000
The main function feeds integers from 2 through 99,999 into the pipeline. Its output begins 2, 3, 5, 7, 11, 13 and ends with 99989 and 99991.
Visualizes candidate numbers passing through prime-filtering stages. section 9.2.7
Figure 9.14 When a new prime is found, we start a new goroutine that filters multiples of that new prime.
Shows how discovering a prime extends the pipeline with another filtering goroutine. section 9.2.7
