From 6487d41455c82fd253651513dad9587a3be830c3 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Thu, 24 Oct 2024 16:16:08 +0200 Subject: [PATCH] Exercise 07-05 --- exercises/07_threads/05_channels/src/lib.rs | 12 ++++++++++-- exercises/07_threads/05_channels/tests/insert.rs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) 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); } -- 2.45.2