Final bit of interface cleanup.
This commit is contained in:
parent
9faa96d307
commit
41afc07bfa
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user