use std::num::NonZeroU64;
use std::thread;
use afire::{Content, Method, Response, Server};
use crate::Example;
pub struct Threading;
impl Example for Threading {
fn name(&self) -> &'static str {
"threading"
}
fn exec(&self) {
let mut server = Server::<()>::new("localhost", 8080);
server.route(Method::GET, "/", |_req| {
Response::new()
.text(format!(
"Hello from thread number {:#?}!",
unsafe { std::mem::transmute::<_, NonZeroU64>(thread::current().id()) }.get()
- 1
))
.content(Content::TXT)
});
server.start_threaded(8).unwrap();
}
}