pub trait FutureExt {
// Required method
fn with_timeout(
self,
timeout: Duration,
executor: &BackgroundExecutor,
) -> WithTimeout<Self>
where Self: Sized;
}Expand description
Adds timeout combinators to futures.
Required Methods§
Sourcefn with_timeout(
self,
timeout: Duration,
executor: &BackgroundExecutor,
) -> WithTimeout<Self>where
Self: Sized,
fn with_timeout(
self,
timeout: Duration,
executor: &BackgroundExecutor,
) -> WithTimeout<Self>where
Self: Sized,
Limits how long the future may wait for a result.
The result is Err(Timeout) if timeout elapses before the future completes. The
timer comes from executor, so tests can advance it with the simulated clock.
§Examples
use std::time::Duration;
use gpui::{FutureExt, TestApp};
let app = TestApp::new();
let slow = app.background_executor().timer(Duration::from_secs(60));
let result = app
.foreground_executor()
.block_test(slow.with_timeout(Duration::from_secs(1), app.background_executor()));
assert!(result.is_err());Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".