]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-8827.rs
Rollup merge of #23847 - bcoopers:read_clarification, r=sfackler
[rust.git] / src / test / run-pass / issue-8827.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(std_misc)]
12
13 use std::thread;
14 use std::sync::mpsc::{channel, Receiver};
15
16 fn periodical(n: isize) -> Receiver<bool> {
17     let (chan, port) = channel();
18     thread::spawn(move|| {
19         loop {
20             for _ in 1..n {
21                 match chan.send(false) {
22                     Ok(()) => {}
23                     Err(..) => break,
24                 }
25             }
26             match chan.send(true) {
27                 Ok(()) => {}
28                 Err(..) => break
29             }
30         }
31     });
32     return port;
33 }
34
35 fn integers() -> Receiver<isize> {
36     let (chan, port) = channel();
37     thread::spawn(move|| {
38         let mut i = 1;
39         loop {
40             match chan.send(i) {
41                 Ok(()) => {}
42                 Err(..) => break,
43             }
44             i = i + 1;
45         }
46     });
47     return port;
48 }
49
50 fn main() {
51     let ints = integers();
52     let threes = periodical(3);
53     let fives = periodical(5);
54     for _ in 1..100 {
55         match (ints.recv().unwrap(), threes.recv().unwrap(), fives.recv().unwrap()) {
56             (_, true, true) => println!("FizzBuzz"),
57             (_, true, false) => println!("Fizz"),
58             (_, false, true) => println!("Buzz"),
59             (i, false, false) => println!("{}", i)
60         }
61     }
62 }