Separated message functions.

This commit is contained in:
Jeff Baskin 2023-04-12 18:33:39 -04:00
parent 448de012d3
commit 30c9562542

View File

@ -270,24 +270,30 @@ impl Cache {
Ok(Self { channel: channel }) Ok(Self { channel: channel })
} }
async fn start(&self) { async fn query(&self, qry: CacheQuery) {
loop { for id in qry.ids {
match self.channel.recv().await.unwrap() {
ToCache::Query(data) => {
for id in data.ids {
if id == ENTRY { if id == ENTRY {
let mut holder = HashMap::new(); let mut holder = HashMap::new();
holder.insert(ENTRY.to_string(), DataType::new("store")); holder.insert(ENTRY.to_string(), DataType::new("store"));
data.reply.send(FromCache::Data(holder)).await.unwrap(); qry.reply.send(FromCache::Data(holder)).await.unwrap();
} else { } else {
data.reply qry.reply
.send(FromCache::Error(MTTError::new("fred"))) .send(FromCache::Error(MTTError::new("fred")))
.await .await
.unwrap(); .unwrap();
} }
} }
} }
ToCache::Commit(data) => data.reply.send(FromCache::Ok).await.unwrap(),
async fn commit(&self, commit: CacheCommit) {
commit.reply.send(FromCache::Ok).await.unwrap();
}
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,
} }
} }
} }
@ -363,6 +369,12 @@ mod caches {
_ => assert!(false, "{:?} should have been an error.", result), _ => assert!(false, "{:?} should have been an error.", result),
} }
} }
#[async_std::test]
async fn add_database_commit() {
//let dir = tempdir().unwrap();
//let s_cache = start_cache(dir.path()).await;
}
} }
pub async fn start_db<P>(_dir: P) -> Result<MoreThanText, MTTError> pub async fn start_db<P>(_dir: P) -> Result<MoreThanText, MTTError>