From 30c9562542adf6ba8360a441d5422174813e62b9 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Wed, 12 Apr 2023 18:33:39 -0400 Subject: [PATCH] Separated message functions. --- src/morethantext/mod.rs | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index acf0d8f..9666256 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -270,24 +270,30 @@ impl Cache { Ok(Self { channel: channel }) } + async fn query(&self, qry: CacheQuery) { + for id in qry.ids { + if id == ENTRY { + let mut holder = HashMap::new(); + holder.insert(ENTRY.to_string(), DataType::new("store")); + qry.reply.send(FromCache::Data(holder)).await.unwrap(); + } else { + qry.reply + .send(FromCache::Error(MTTError::new("fred"))) + .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(data) => { - for id in data.ids { - if id == ENTRY { - let mut holder = HashMap::new(); - holder.insert(ENTRY.to_string(), DataType::new("store")); - data.reply.send(FromCache::Data(holder)).await.unwrap(); - } else { - data.reply - .send(FromCache::Error(MTTError::new("fred"))) - .await - .unwrap(); - } - } - } - ToCache::Commit(data) => data.reply.send(FromCache::Ok).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), } } + + #[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

(_dir: P) -> Result