3 // don't run it - goes forever
5 // Copyright 2009 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
11 // Send the sequence 2, 3, 4, ... to channel 'ch'.
12 func Generate(ch chan<- int) {
14 ch <- i // Send 'i' to channel 'ch'.
18 // Copy the values from channel 'in' to channel 'out',
19 // removing those divisible by 'prime'.
20 func Filter(in <-chan int, out chan<- int, prime int) {
22 i := <-in // Receive value of new variable 'i' from 'in'.
24 out <- i // Send 'i' to channel 'out'.
29 // The prime sieve: Daisy-chain Filter processes together.
31 ch := make(chan int) // Create a new channel.
32 go Generate(ch) // Start Generate() as a subprocess.
37 go Filter(ch, ch1, prime)