Cleaned up the cache interface.
This commit is contained in:
parent
30c9562542
commit
9faa96d307
@ -270,30 +270,37 @@ impl Cache {
|
||||
Ok(Self { channel: channel })
|
||||
}
|
||||
|
||||
async fn query(&self, qry: CacheQuery) {
|
||||
for id in qry.ids {
|
||||
async fn query(&self, qry: &Vec<String>) -> Result<HashMap<String, DataType>, MTTError> {
|
||||
let mut output = HashMap::new();
|
||||
for id in qry {
|
||||
if id == ENTRY {
|
||||
let mut holder = HashMap::new();
|
||||
holder.insert(ENTRY.to_string(), DataType::new("store"));
|
||||
qry.reply.send(FromCache::Data(holder)).await.unwrap();
|
||||
output.insert(ENTRY.to_string(), DataType::new("store"));
|
||||
} else {
|
||||
qry.reply
|
||||
.send(FromCache::Error(MTTError::new("fred")))
|
||||
.await
|
||||
.unwrap();
|
||||
return Err(MTTError::new("fred"))
|
||||
}
|
||||
}
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
async fn commit(&self, commit: CacheCommit) {
|
||||
commit.reply.send(FromCache::Ok).await.unwrap();
|
||||
async fn commit(&self) -> Result<(), MTTError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn start(&self) {
|
||||
loop {
|
||||
match self.channel.recv().await.unwrap() {
|
||||
ToCache::Query(qry) => self.query(qry).await,
|
||||
ToCache::Commit(commit) => self.commit(commit).await,
|
||||
ToCache::Query(qry) => {
|
||||
match self.query(&qry.ids).await {
|
||||
Ok(data) => qry.reply.send(FromCache::Data(data)).await.unwrap(),
|
||||
Err(error) => qry.reply.send(FromCache::Error(error)).await.unwrap(),
|
||||
}
|
||||
},
|
||||
ToCache::Commit(commit) => {
|
||||
match self.commit().await {
|
||||
Ok(_) => commit.reply.send(FromCache::Ok).await.unwrap(),
|
||||
Err(error) => commit.reply.send(FromCache::Error(error)).await.unwrap(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user