Skip to content

Instantly share code, notes, and snippets.

@computermouth
Created January 4, 2023 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computermouth/e9052ebc5aaca9c29bcf506df1572d21 to your computer and use it in GitHub Desktop.
Save computermouth/e9052ebc5aaca9c29bcf506df1572d21 to your computer and use it in GitHub Desktop.
// 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