clean up veilid state processing

This commit is contained in:
John Smith
2022-01-18 18:28:22 -05:00
parent 1b6864bf22
commit 205a6a8fd1
5 changed files with 54 additions and 41 deletions
+1 -13
View File
@@ -68,24 +68,12 @@ where
// pub fn clear_state_change_callback(&self) {
// self.inner.lock().callback = None;
// }
pub fn state_eventual_instance(&self) -> (T::State, EventualValueCloneFuture<T::State>) {
let inner = self.inner.lock();
(inner.state, inner.eventual.instance())
}
pub async fn send_state_update(&self) {
let (state, callback, eventual) = {
let mut inner = self.inner.lock();
let eventual =
core::mem::replace(&mut inner.eventual, EventualValueClone::<T::State>::new());
(inner.state, inner.callback.clone(), eventual)
};
if let Some(cb) = callback {
cb(state, state).await;
}
eventual.resolve(state).await;
}
pub async fn consume(&self, input: &T::Input) -> Result<Option<T::Output>, ()> {
let current_state = self.inner.lock().state;