| 1 |
#[cfg(feature = "select")] |
| 2 |
use flume::Selector; |
| 3 |
|
| 4 |
#[cfg(feature = "select")] |
| 5 |
fn main() { |
| 6 |
|
| 7 |
let (red_tx, red_rx) = flume::unbounded(); |
| 8 |
let (blue_tx, blue_rx) = flume::unbounded(); |
| 9 |
|
| 10 |
|
| 11 |
std::thread::spawn(move || { let _ = red_tx.send("Red"); }); |
| 12 |
std::thread::spawn(move || { let _ = blue_tx.send("Blue"); }); |
| 13 |
|
| 14 |
|
| 15 |
let winner = Selector::new() |
| 16 |
.recv(&red_rx, |msg| msg) |
| 17 |
.recv(&blue_rx, |msg| msg) |
| 18 |
.wait() |
| 19 |
.unwrap(); |
| 20 |
|
| 21 |
println!("{} won!", winner); |
| 22 |
} |
| 23 |
|
| 24 |
#[cfg(not(feature = "select"))] |
| 25 |
fn main() {} |