Final bit of interface cleanup.

This commit is contained in:
Jeff Baskin 2023-04-15 10:18:56 -04:00
parent 9faa96d307
commit 41afc07bfa

View File

@ -258,16 +258,14 @@ mod mtt {
} }
} }
struct Cache { struct Cache;
channel: Receiver<ToCache>,
}
impl Cache { impl Cache {
async fn new<P>(_dir: P, channel: Receiver<ToCache>) -> Result<Self, MTTError> async fn new<P>(_dir: P) -> Result<Self, MTTError>
where where
P: Into<PathBuf>, P: Into<PathBuf>,
{ {
Ok(Self { channel: channel }) Ok(Self {})
} }
async fn query(&self, qry: &Vec<String>) -> Result<HashMap<String, DataType>, MTTError> { async fn query(&self, qry: &Vec<String>) -> Result<HashMap<String, DataType>, MTTError> {
@ -276,7 +274,7 @@ impl Cache {
if id == ENTRY { if id == ENTRY {
output.insert(ENTRY.to_string(), DataType::new("store")); output.insert(ENTRY.to_string(), DataType::new("store"));
} else { } else {
return Err(MTTError::new("fred")) return Err(MTTError::new("fred"));
} }
} }
Ok(output) Ok(output)
@ -286,9 +284,9 @@ impl Cache {
Ok(()) Ok(())
} }
async fn start(&self) { async fn start(&self, listener: Receiver<ToCache>) {
loop { loop {
match self.channel.recv().await.unwrap() { match listener.recv().await.unwrap() {
ToCache::Query(qry) => { ToCache::Query(qry) => {
match self.query(&qry.ids).await { match self.query(&qry.ids).await {
Ok(data) => qry.reply.send(FromCache::Data(data)).await.unwrap(), Ok(data) => qry.reply.send(FromCache::Data(data)).await.unwrap(),
@ -318,8 +316,8 @@ mod caches {
let (s, r) = unbounded(); let (s, r) = unbounded();
let datadir = dir.into(); let datadir = dir.into();
spawn(async move { spawn(async move {
let cache = Cache::new(datadir, r).await.unwrap(); let cache = Cache::new(datadir).await.unwrap();
cache.start().await; cache.start(r).await;
}); });
s s
} }
@ -373,7 +371,7 @@ mod caches {
let result = r.recv().await.unwrap(); let result = r.recv().await.unwrap();
match result { match result {
FromCache::Ok => (), FromCache::Ok => (),
_ => assert!(false, "{:?} should have been an error.", result), _ => assert!(false, "{:?} should have been an Ok.", result),
} }
} }