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