Skip to main content

Extensions

Trait Extensions 

Source
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§

Source

fn delay(self, timeout: Duration) -> impl Future<Output = Self::Output>
where Self: Future,

延迟指定时间后才执行

Source

fn deadline( self, timeout: Duration, ) -> impl Future<Output = Option<Self::Output>>
where Self: Future,

如果在指定时间(相对时间)内未完成,则提前终止,并返回None

Source

fn seq<T>(self, future: T) -> impl Future<Output = (Self::Output, T::Output)>
where Self: Future, T: Future,

顺序执行,都完成后一起返回

Source

fn or<T>( self, future: T, ) -> impl Future<Output = (Option<Self::Output>, Option<T::Output>)>
where Self: Future, T: Future,

并发执行, 任意一个完成则返回,注意如果另一个已经启动但未完成,则会触发abort, 参见TaskContext.

Source

fn and<T>(self, future: T) -> impl Future<Output = (Self::Output, T::Output)>
where Self: Future, T: Future,

并发执行,两个都完成后才返回,

Source

fn ready<F: FnMut(Self::Output) -> R, R>(self, f: F) -> impl Future<Output = R>
where Self: Future,

相当于Poll::map调用,只是适用返回值为impl Future的非async函数.

Source

fn wait_entry<const N: usize>(self) -> impl Future<Output = Self::Output>
where Self: Future,

👎Deprecated:

不再需要显示调用,一个异步任务缺省支持32个fd,如果的确需要更多,可利用runtime::task::spawn_with中的参数attr指定fdset的最大值

可消除wait_event(AioFd::wait)每次注册,取消注册动作,在异步任务全生命周期只会注册一次 结合POLLET,可以提升io效率 N: 表示使用的最多Fd数量

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T: Future> Extensions for T