Make future not hold strong handles
This commit is contained in:
parent
3ecada3b47
commit
d1b59e008f
1 changed files with 7 additions and 6 deletions
|
@ -317,10 +317,11 @@ impl States {
|
|||
&self,
|
||||
id: impl Into<Option<&'b str>>,
|
||||
) -> Result<Box<dyn FutureStateChange>> {
|
||||
let state = id.into().map(|id| self.get_state(id)).transpose()?;
|
||||
let current_state = self.current_state.clone();
|
||||
let state: Option<Arc<State>> = id.into().map(|id| self.get_state(id)).transpose()?;
|
||||
let weak_state = state.map(|s| Arc::downgrade(&s));
|
||||
let weak_current_state = Arc::downgrade(&self.current_state);
|
||||
let gui_handler = if self.control_top_gui {
|
||||
Some(self.gui_handler.clone())
|
||||
Some(Arc::downgrade(&self.gui_handler))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -328,9 +329,9 @@ impl States {
|
|||
|
||||
Ok(Box::new(move || {
|
||||
Self::_set_state(
|
||||
state.clone(),
|
||||
&mut *current_state.lock().unwrap(),
|
||||
gui_handler.clone(),
|
||||
weak_state.as_ref().map(|w| w.upgrade()).flatten(),
|
||||
&mut *weak_current_state.upgrade().unwrap().lock().unwrap(),
|
||||
gui_handler.as_ref().map(|h| h.upgrade()).flatten(),
|
||||
logging,
|
||||
)
|
||||
}))
|
||||
|
|
Loading…
Reference in a new issue