diff options
author | Rob Pike <r@golang.org> | 2008-07-15 20:52:07 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2008-07-15 20:52:07 -0700 |
commit | 33101926f9196bcf872ab5560543f30660d17e2d (patch) | |
tree | 79b8077b92aeb361c3e3fff67111ab50192a3d19 /test/sieve.go | |
parent | f550cd67e0de68cc5a4757e05ccaf1498565bec9 (diff) | |
download | go-33101926f9196bcf872ab5560543f30660d17e2d.tar.gz go-33101926f9196bcf872ab5560543f30660d17e2d.zip |
channel tests with new syntax
SVN=127436
Diffstat (limited to 'test/sieve.go')
-rw-r--r-- | test/sieve.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/test/sieve.go b/test/sieve.go index 365252260c..c55477caf3 100644 --- a/test/sieve.go +++ b/test/sieve.go @@ -7,34 +7,34 @@ package main // Send the sequence 2, 3, 4, ... to channel 'ch'. -func Generate(ch *chan> int) { - for i := 2; ; i++ { - >ch = i // Send 'i' to channel 'ch'. - } +func Generate(ch *chan-< int) { + for i := 2; ; i++ { + ch -< i // Send 'i' to channel 'ch'. + } } // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. -func Filter(in *chan< int, out *chan> int, prime int) { - for { - i := <in // Receive value of new variable 'i' from 'in'. - if i % prime != 0 { - >out = i // Send 'i' to channel 'out'. - } - } +func Filter(in *chan<- int, out *chan-< int, prime int) { + for { + i := <-in // Receive value of new variable 'i' from 'in'. + if i % prime != 0 { + out -< i // Send 'i' to channel 'out'. + } + } } // The prime sieve: Daisy-chain Filter processes together. func Sieve() { - ch := new(chan int); // Create a new channel. - go Generate(ch); // Start Generate() as a subprocess. - for { - prime := <ch; - print prime, "\n"; - ch1 := new(chan int); - go Filter(ch, ch1, prime); - ch = ch1 - } + ch := new(chan int); // Create a new channel. + go Generate(ch); // Start Generate() as a subprocess. + for { + prime := <-ch; + print prime, "\n"; + ch1 := new(chan int); + go Filter(ch, ch1, prime); + ch = ch1 + } } func main() { |