common/emgauwa-controller/src/utils.rs

33 lines
746 B
Rust
Raw Normal View History

2023-12-07 03:30:33 +00:00
use std::sync::Arc;
use actix::Addr;
use emgauwa_lib::errors::EmgauwaError;
use emgauwa_lib::models::Controller;
2023-12-07 03:30:33 +00:00
use tokio::sync::Notify;
use crate::app_state;
use crate::app_state::AppState;
2023-12-07 03:30:33 +00:00
pub async fn app_state_get_this(app_state: &Addr<AppState>) -> Result<Controller, EmgauwaError> {
app_state
.send(app_state::GetThis {})
.await
.map_err(EmgauwaError::from)
}
2023-12-07 03:30:33 +00:00
pub async fn app_state_get_notifier(
app_state: &Addr<AppState>,
) -> Result<Arc<Notify>, EmgauwaError> {
app_state
.send(app_state::GetNotifier {})
.await
.map_err(EmgauwaError::from)
}
pub async fn app_state_reload(app_state: &Addr<AppState>) -> Result<(), EmgauwaError> {
app_state
.send(app_state::Reload {})
.await
.map_err(EmgauwaError::from)?
}