diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index a861b82ff6..946d1bf1f6 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -178,7 +178,14 @@ impl TestAppContext { &self.foreground_executor } - fn new(&mut self, build_entity: impl FnOnce(&mut Context) -> T) -> Entity { + /// Builds an entity that is owned by the application. + /// + /// The given function will be invoked with a [`Context`] and must return an object representing the entity. An + /// [`Entity`] handle will be returned, which can be used to access the entity in a context. + pub fn new( + &mut self, + build_entity: impl FnOnce(&mut Context) -> T, + ) -> Entity { let mut cx = self.app.borrow_mut(); cx.new(build_entity) } diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs index affca7b1b4..0983e352f5 100644 --- a/crates/gpui/src/executor.rs +++ b/crates/gpui/src/executor.rs @@ -95,6 +95,13 @@ where .spawn(self.log_tracked_err(*location)) .detach(); } + + /// Convert a Task> to a Task<()> that logs all errors. + pub fn log_err_in_task(self, cx: &App) -> Task> { + let location = core::panic::Location::caller(); + cx.foreground_executor() + .spawn(async move { self.log_tracked_err(*location).await }) + } } impl Future for Task {