| 1 |
// Copyright (c) 2015 CtrlC developers |
| 2 |
// Licensed under the Apache License, Version 2.0 |
| 3 |
// <LICENSE-APACHE or |
| 4 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
| 5 |
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, |
| 6 |
// at your option. All files in the project carrying such |
| 7 |
// notice may not be copied, modified, or distributed except |
| 8 |
// according to those terms. |
| 9 |
|
| 10 |
use ctrlc; |
| 11 |
use std::sync::mpsc::channel; |
| 12 |
|
| 13 |
fn main() { |
| 14 |
let (tx, rx) = channel(); |
| 15 |
|
| 16 |
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel.")) |
| 17 |
.expect("Error setting Ctrl-C handler"); |
| 18 |
|
| 19 |
println!("Waiting for Ctrl-C..."); |
| 20 |
rx.recv().expect("Could not receive from channel."); |
| 21 |
println!("Got it! Exiting..."); |
| 22 |
} |