Skip to main content

TaskExt

Trait TaskExt 

Source
pub trait TaskExt<T, E> {
    // Required methods
    fn detach_and_log_err(self, cx: &App);
    fn detach_and_log_err_with_backtrace(self, cx: &App);
}
Expand description

Extension methods for tasks that produce a Result.

The methods log a failure instead of dropping it silently, so use them for work that you start and don’t wait for.

§Examples

use gpui::{TaskExt, TestApp};

let mut app = TestApp::new();
app.update(|cx| {
    let save = cx.background_executor().spawn(async { Err::<(), _>("disk full") });
    save.detach_and_log_err(cx);
});

Required Methods§

Source

fn detach_and_log_err(self, cx: &App)

Runs the task to completion in the background. If it fails, the error is written to the log.

Source

fn detach_and_log_err_with_backtrace(self, cx: &App)

Like TaskExt::detach_and_log_err, but logs the error with Debug formatting, so an anyhow::Error includes its backtrace. Use it when you need the backtrace, and the other method otherwise.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, E> TaskExt<T, E> for Task<Result<T, E>>
where T: 'static, E: 'static + Display + Debug,