refactor: let state use either local or backend
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -13,12 +13,21 @@ pub struct State {
|
||||
pub querier: Querier,
|
||||
}
|
||||
|
||||
pub enum Backend {
|
||||
Local,
|
||||
Remote,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
pub async fn new(backend: Backend) -> anyhow::Result<Self> {
|
||||
let storage = Storage::new();
|
||||
let engine = storage.load()?;
|
||||
let events = Events::default();
|
||||
let engine = SharedEngine::from(engine);
|
||||
let querier = match backend {
|
||||
Backend::Local => Querier::local(&engine),
|
||||
Backend::Remote => Querier::remote().await?,
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
engine: engine.clone(),
|
||||
@@ -26,7 +35,7 @@ impl State {
|
||||
events: events.clone(),
|
||||
|
||||
commander: Commander::new(engine.clone(), storage, events)?,
|
||||
querier: Querier::local(&engine),
|
||||
querier,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user