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.
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.
13 use std::thread::Thread;
14 use std::sync::mpsc::{channel, Receiver};
16 fn periodical(n: isize) -> Receiver<bool> {
17 let (chan, port) = channel();
18 Thread::spawn(move|| {
21 match chan.send(false) {
26 match chan.send(true) {
35 fn integers() -> Receiver<isize> {
36 let (chan, port) = channel();
37 Thread::spawn(move|| {
51 let ints = integers();
52 let threes = periodical(3);
53 let fives = periodical(5);
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)