Final bit of interface cleanup.

This commit is contained in:
Jeff Baskin 2023-04-15 10:18:56 -04:00
parent 9faa96d307
commit 41afc07bfa
1 changed files with 9 additions and 11 deletions

View File

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