diff --git a/src/main.rs b/src/main.rs index 5fc6d36..9a4e4ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use log::info; use std::io::{Read, Write}; use std::net::{TcpListener, TcpStream}; -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{Arc, Mutex, mpsc}; use std::{sync, thread}; static GET: &'static [u8] = b"GET / HTTP/1.1\r\n"; @@ -13,8 +13,11 @@ struct Worker { impl Worker { fn new(id: usize, receiver: Arc>>) -> Worker { - let thread = thread::spawn(|| { - receiver; + let thread = thread::spawn(move || { + loop { + let job = receiver.lock().unwrap().recv().unwrap(); + job(); + } }); Worker { id, thread } } @@ -43,7 +46,7 @@ impl ThreadPool { } } -struct Job {} +type Job = Box; fn main() -> std::io::Result<()> { env_logger::init();