pub trait Extensions {
// Required methods
fn delay(self, timeout: Duration) -> impl Future<Output = Self::Output>
where Self: Future;
fn deadline(
self,
timeout: Duration,
) -> impl Future<Output = Option<Self::Output>>
where Self: Future;
fn seq<T>(
self,
future: T,
) -> impl Future<Output = (Self::Output, T::Output)>
where Self: Future,
T: Future;
fn or<T>(
self,
future: T,
) -> impl Future<Output = (Option<Self::Output>, Option<T::Output>)>
where Self: Future,
T: Future;
fn and<T>(
self,
future: T,
) -> impl Future<Output = (Self::Output, T::Output)>
where Self: Future,
T: Future;
fn ready<F: FnMut(Self::Output) -> R, R>(
self,
f: F,
) -> impl Future<Output = R>
where Self: Future;
fn wait_entry<const N: usize>(self) -> impl Future<Output = Self::Output>
where Self: Future;
}Expand description
提供不同future的各种组合能力
Required Methods§
Sourcefn delay(self, timeout: Duration) -> impl Future<Output = Self::Output>where
Self: Future,
fn delay(self, timeout: Duration) -> impl Future<Output = Self::Output>where
Self: Future,
延迟指定时间后才执行
Sourcefn deadline(
self,
timeout: Duration,
) -> impl Future<Output = Option<Self::Output>>where
Self: Future,
fn deadline(
self,
timeout: Duration,
) -> impl Future<Output = Option<Self::Output>>where
Self: Future,
如果在指定时间(相对时间)内未完成,则提前终止,并返回None
Sourcefn or<T>(
self,
future: T,
) -> impl Future<Output = (Option<Self::Output>, Option<T::Output>)>
fn or<T>( self, future: T, ) -> impl Future<Output = (Option<Self::Output>, Option<T::Output>)>
并发执行, 任意一个完成则返回,注意如果另一个已经启动但未完成,则会触发abort, 参见TaskContext.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".