From: Greg Burri Date: Thu, 24 Oct 2024 14:16:08 +0000 (+0200) Subject: Exercise 07-05 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=6487d41455c82fd253651513dad9587a3be830c3;p=rust_exercises.git Exercise 07-05 --- diff --git a/exercises/07_threads/05_channels/src/lib.rs b/exercises/07_threads/05_channels/src/lib.rs index f049bf3..b8da5b5 100644 --- a/exercises/07_threads/05_channels/src/lib.rs +++ b/exercises/07_threads/05_channels/src/lib.rs @@ -4,7 +4,7 @@ pub mod data; pub mod store; pub enum Command { - Insert(todo!()), + Insert(data::TicketDraft), } // Start the system by spawning the server the thread. @@ -20,4 +20,12 @@ pub fn launch() -> Sender { // Enter a loop: wait for a command to show up in // the channel, then execute it, then start waiting // for the next command. -pub fn server(receiver: Receiver) {} +pub fn server(receiver: Receiver) { + let mut store = store::TicketStore::new(); + loop { + match receiver.recv() { + Ok(Command::Insert(ticket)) => _ = store.add_ticket(ticket), + Err(err) => println!("Error during receive: {:?}", err), + } + } +} diff --git a/exercises/07_threads/05_channels/tests/insert.rs b/exercises/07_threads/05_channels/tests/insert.rs index 651a467..bb72b1a 100644 --- a/exercises/07_threads/05_channels/tests/insert.rs +++ b/exercises/07_threads/05_channels/tests/insert.rs @@ -26,7 +26,7 @@ fn ready() { // since our server doesn't expose any **read** actions. // We have no way to know if the inserts are actually happening and if they // are happening correctly. - let move_forward = false; + let move_forward = true; assert!(move_forward); }