1 // $G $F.go && $L $F.$A # don't run it - goes forever
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
9 // Send the sequence 2, 3, 4, ... to channel 'ch'.
10 func Generate(ch chan<- int) {
12 ch <- i // Send 'i' to channel 'ch'.
16 // Copy the values from channel 'in' to channel 'out',
17 // removing those divisible by 'prime'.
18 func Filter(in <-chan int, out chan<- int, prime int) {
20 i := <-in; // Receive value of new variable 'i' from 'in'.
22 out <- i // Send 'i' to channel 'out'.
27 // The prime sieve: Daisy-chain Filter processes together.
29 ch := make(chan int); // Create a new channel.
30 go Generate(ch); // Start Generate() as a subprocess.
34 ch1 := make(chan int);
35 go Filter(ch, ch1, prime);