From 41afc07bfa31c0a65746738e7eae6ec3d311af56 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sat, 15 Apr 2023 10:18:56 -0400 Subject: [PATCH] Final bit of interface cleanup. --- src/morethantext/mod.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index bbb1e88..80df136 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -258,16 +258,14 @@ mod mtt { } } -struct Cache { - channel: Receiver, -} +struct Cache; impl Cache { - async fn new

(_dir: P, channel: Receiver) -> Result + async fn new

(_dir: P) -> Result where P: Into, { - Ok(Self { channel: channel }) + Ok(Self {}) } async fn query(&self, qry: &Vec) -> Result, 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) { 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), } }