Allow effects to be flushed before TestAppContext::update callback completes
This commit is contained in:
parent
97a8a8ed43
commit
620eedb727
2 changed files with 6 additions and 5 deletions
|
@ -313,8 +313,11 @@ impl TestAppContext {
|
||||||
|
|
||||||
pub fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
|
pub fn update<T, F: FnOnce(&mut MutableAppContext) -> T>(&mut self, callback: F) -> T {
|
||||||
let mut state = self.0.borrow_mut();
|
let mut state = self.0.borrow_mut();
|
||||||
state.pending_flushes += 1;
|
// Don't increment pending flushes in order to effects to be flushed before the callback
|
||||||
|
// completes, which is helpful in tests.
|
||||||
let result = callback(&mut *state);
|
let result = callback(&mut *state);
|
||||||
|
// Flush effects after the callback just in case there are any. This can happen in edge
|
||||||
|
// cases such as the closure dropping handles.
|
||||||
state.flush_effects();
|
state.flush_effects();
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -895,7 +898,7 @@ impl MutableAppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_effects(&mut self) {
|
fn flush_effects(&mut self) {
|
||||||
self.pending_flushes -= 1;
|
self.pending_flushes = self.pending_flushes.saturating_sub(1);
|
||||||
|
|
||||||
if !self.flushing_effects && self.pending_flushes == 0 {
|
if !self.flushing_effects && self.pending_flushes == 0 {
|
||||||
self.flushing_effects = true;
|
self.flushing_effects = true;
|
||||||
|
|
|
@ -515,13 +515,11 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.dispatch_action(window_id, vec![pane_2.id()], "pane:close_active_item", ());
|
ctx.dispatch_action(window_id, vec![pane_2.id()], "pane:close_active_item", ());
|
||||||
});
|
|
||||||
|
|
||||||
app.read(|ctx| {
|
|
||||||
let w = workspace_view.read(ctx);
|
let w = workspace_view.read(ctx);
|
||||||
assert_eq!(w.panes.len(), 1);
|
assert_eq!(w.panes.len(), 1);
|
||||||
assert_eq!(w.active_pane(), &pane_1);
|
assert_eq!(w.active_pane(), &pane_1);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue