1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Primes example, using channels and "goroutines"

            Channel numbers = new Channel();

            GoRoutines.Go(() => { for (int k = 2; ; k++) numbers.Send(k);  });

            Channel channel = numbers;

            int prime = 0;

            while (prime < 1000)
            {
                prime = (int)channel.Receive();

                Console.WriteLine(prime);

                Channel newchannel = new Channel();

                GoRoutines.Go((input, output, p) =>
                {
                    while (true)
                    {
                        int number = (int)input.Receive();

                        if ((number % p) != 0)
                            output.Send(number);
                    }
                }, channel, newchannel, prime);

                channel = newchannel;
            }