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.
11 // ignore-emscripten no threads support
16 use std::sync::mpsc::{channel, Receiver};
18 fn periodical(n: isize) -> Receiver<bool> {
19 let (chan, port) = channel();
20 thread::spawn(move|| {
23 match chan.send(false) {
28 match chan.send(true) {
37 fn integers() -> Receiver<isize> {
38 let (chan, port) = channel();
39 thread::spawn(move|| {
53 let ints = integers();
54 let threes = periodical(3);
55 let fives = periodical(5);
57 match (ints.recv().unwrap(), threes.recv().unwrap(), fives.recv().unwrap()) {
58 (_, true, true) => println!("FizzBuzz"),
59 (_, true, false) => println!("Fizz"),
60 (_, false, true) => println!("Buzz"),
61 (i, false, false) => println!("{}", i)