Got the client and engine connecting.

This commit is contained in:
2023-06-20 11:51:32 -04:00
parent dd1c45ddbe
commit ecfc8fdf90
3 changed files with 90 additions and 20 deletions

View File

@ -13,6 +13,23 @@ use store::Store;
const ENTRY: &str = "EntryPoint";
#[derive(Debug)]
pub struct CacheGet {
id: String,
result: Sender<FromCache>,
}
#[derive(Debug)]
pub enum ToCache {
Get(CacheGet),
}
#[derive(Debug)]
pub enum FromCache {
Str(Store),
Error(MTTError),
}
#[derive(Clone, Debug)]
struct Data<D> {
id: Option<String>,
@ -33,20 +50,29 @@ impl<D> Data<D> {
#[derive(Clone)]
pub struct MoreThanText {
to_cache: Sender<String>,
to_cache: Sender<ToCache>,
entry: Data<Store>,
}
impl MoreThanText {
fn new(to_cache: Sender<String>) -> Self {
fn new(to_cache: Sender<ToCache>) -> Self {
Self {
to_cache: to_cache,
entry: Data::from_id(ENTRY),
}
}
async fn session(&self) -> Store {
Store::new()
async fn session(&self) -> Result<Store, MTTError> {
let (s, r) = unbounded();
let msg = CacheGet {
id: ENTRY.to_string(),
result: s,
};
self.to_cache.send(ToCache::Get(msg)).await.unwrap();
match r.recv().await.unwrap() {
FromCache::Str(store) => Ok(store),
FromCache::Error(err) => Err(err),
}
}
}
@ -61,7 +87,7 @@ mod mtt {
let mtt = start_db(dir.path()).await.unwrap();
assert_eq!(mtt.entry.id, Some(ENTRY.to_string()));
assert!(mtt.entry.data.is_none());
let store = mtt.session().await;
let store = mtt.session().await.unwrap();
let expected: Vec<String> = Vec::new();
assert_eq!(store.list(), expected);
}