Added queue with a little clean up.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
queue::{Message, MsgType},
|
||||
queue::{Message, MsgType, Queue},
|
||||
utils::GenID,
|
||||
};
|
||||
use std::{
|
||||
@ -62,10 +62,6 @@ impl ClientRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_storage() -> Arc<Mutex<HashMap<Uuid, Sender<Reply>>>> {
|
||||
Arc::new(Mutex::new(HashMap::new()))
|
||||
}
|
||||
|
||||
fn get_id<'a>(
|
||||
gen: &mut impl Iterator<Item = Uuid>,
|
||||
data: &HashMap<Uuid, Sender<Reply>>,
|
||||
@ -78,7 +74,6 @@ impl ClientRegistry {
|
||||
}
|
||||
|
||||
pub fn add(&mut self, tx: Sender<Reply>) -> Uuid {
|
||||
let id = Uuid::new_v4();
|
||||
let mut reg = self.registry.lock().unwrap();
|
||||
let mut gen_id = GenID::new();
|
||||
let id = ClientRegistry::get_id(&mut gen_id, ®);
|
||||
@ -158,7 +153,7 @@ impl ClientLink {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(&mut self, req: Request) -> Receiver<Reply> {
|
||||
pub fn send(&mut self, _req: Request) -> Receiver<Reply> {
|
||||
let (tx, rx) = channel();
|
||||
let mut msg = Message::new(MsgType::ClientRequest);
|
||||
let id = self.registry.add(tx);
|
||||
@ -211,7 +206,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start() -> ClientLink {
|
||||
pub fn start(_queue: Queue) -> ClientLink {
|
||||
let (tx, rx) = channel();
|
||||
let mut client = Client::new(rx);
|
||||
let link = ClientLink::new(tx, client.get_registry());
|
||||
@ -242,7 +237,8 @@ mod clients {
|
||||
|
||||
#[test]
|
||||
fn start_client() {
|
||||
let mut link = Client::start();
|
||||
let queue = Queue::new();
|
||||
let mut link = Client::start(queue.clone());
|
||||
let req = create_request();
|
||||
link.send(req);
|
||||
}
|
||||
|
Reference in New Issue
Block a user