Created
January 4, 2023 17:03
-
-
Save computermouth/e9052ebc5aaca9c29bcf506df1572d21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The standard library imports. | |
use std::sync::mpsc::channel; | |
use std::thread::spawn; | |
use std::sync::Mutex; | |
use rouille; | |
fn main() { | |
println!("Hello, world!"); | |
// Create a channel pair. They are distinct types unlike in Go. | |
let (tx, rx) = channel(); | |
let mtx = Mutex::new(tx); | |
// spawn(move || { | |
// }); | |
spawn(move || { | |
rouille::start_server("localhost:9090", move |request| { | |
rouille::router!(request, | |
(GET) (/status) => { | |
rouille::Response::text("ok") | |
}, | |
(GET) (/shutdown) => { | |
mtx.lock().unwrap().send(1).unwrap(); | |
rouille::Response::text("quitting") | |
}, | |
_ => { | |
rouille::Response::empty_404() | |
} | |
) | |
}); | |
}); | |
// Receive the value and ignore the error by calling `unwrap`. | |
println!("received value {:?}", rx.recv().unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment