complete chapter 7
Some checks failed
CI / gravity (push) Has been skipped
CI / build (push) Failing after 14s
CI / is_fresh (push) Successful in 49s
CI / formatter (push) Failing after 17s

This commit is contained in:
2025-05-02 14:11:16 +05:30
parent 4fbee2d894
commit b044878fe8
11 changed files with 90 additions and 31 deletions

View File

@@ -7,23 +7,38 @@ pub mod store;
#[derive(Clone)]
// TODO: flesh out the client implementation.
pub struct TicketStoreClient {}
pub struct TicketStoreClient {
sender: Sender<Command>,
}
impl TicketStoreClient {
// Feel free to panic on all errors, for simplicity.
pub fn insert(&self, draft: TicketDraft) -> TicketId {
todo!()
let (sendr, recvr) = std::sync::mpsc::channel::<TicketId>();
match self.sender.send(Command::Insert {
draft: draft,
response_channel: sendr,
}) {
Ok(a) => {}
_ => {}
}
recvr.recv().ok().unwrap()
}
pub fn get(&self, id: TicketId) -> Option<Ticket> {
todo!()
let (sendr, recvr) = std::sync::mpsc::channel::<Option<Ticket>>();
self.sender.send(Command::Get {
id: id,
response_channel: sendr,
});
recvr.recv().unwrap()
}
}
pub fn launch() -> TicketStoreClient {
let (sender, receiver) = std::sync::mpsc::channel();
std::thread::spawn(move || server(receiver));
todo!()
TicketStoreClient { sender }
}
// No longer public! This becomes an internal detail of the library now.