Add gpui helpers
This commit is contained in:
@@ -178,7 +178,14 @@ impl TestAppContext {
|
||||
&self.foreground_executor
|
||||
}
|
||||
|
||||
fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T> {
|
||||
/// 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<T: 'static>(
|
||||
&mut self,
|
||||
build_entity: impl FnOnce(&mut Context<T>) -> T,
|
||||
) -> Entity<T> {
|
||||
let mut cx = self.app.borrow_mut();
|
||||
cx.new(build_entity)
|
||||
}
|
||||
|
||||
@@ -95,6 +95,13 @@ where
|
||||
.spawn(self.log_tracked_err(*location))
|
||||
.detach();
|
||||
}
|
||||
|
||||
/// Convert a Task<Result<T, E>> to a Task<()> that logs all errors.
|
||||
pub fn log_err_in_task(self, cx: &App) -> Task<Option<T>> {
|
||||
let location = core::panic::Location::caller();
|
||||
cx.foreground_executor()
|
||||
.spawn(async move { self.log_tracked_err(*location).await })
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Future for Task<T> {
|
||||
|
||||
Reference in New Issue
Block a user