Skip to main content

RuntimeTime

Trait RuntimeTime 

pub trait RuntimeTime {
    type Timer: TimerAccess;

    // Required methods
    fn timeout(&self, duration: Duration) -> Timeout<Self::Timer> ⓘ;
    fn timeout_on<F>(
        &self,
        future: F,
        duration: Duration,
    ) -> TimeoutOn<Self::Timer, F> ⓘ
       where F: Future;
    fn sleep(&self, duration: Duration) -> Sleep<Self::Timer> ⓘ;

    // Provided methods
    fn timeout_local(
        _duration: Duration,
    ) -> Result<Timeout<Self::Timer>, LocalRuntimeAccessError>
       where Self: Sized { ... }
    fn timeout_on_local<F>(
        _future: F,
        _duration: Duration,
    ) -> Result<TimeoutOn<Self::Timer, F>, LocalRuntimeAccessError>
       where F: Future,
             Self: Sized { ... }
    fn sleep_local(
        _duration: Duration,
    ) -> Result<Sleep<Self::Timer>, LocalRuntimeAccessError>
       where Self: Sized { ... }
}
Expand description

原服务拥有的计时能力;构造等待值不隐式推进服务。

Required Associated Types§

Required Methods§

Source

fn timeout(&self, duration: Duration) -> Timeout<Self::Timer> ⓘ

准备惰性计时等待;正时长首次poll才取时登记,至少1ms;零时长让出一次且不可取消。

Source

fn timeout_on<F>( &self, future: F, duration: Duration, ) -> TimeoutOn<Self::Timer, F> ⓘ
where F: Future,

按业务优先组合Future与计时;不要求额外Unpin/Send/Sync/’static,完成时撤销另一等待兴趣。

Source

fn sleep(&self, duration: Duration) -> Sleep<Self::Timer> ⓘ

准备短时等待;正时长范围1ms至1s,不返回独立控制句柄(handle),首次poll才开始。

Provided Methods§

Source

fn timeout_local( _duration: Duration, ) -> Result<Timeout<Self::Timer>, LocalRuntimeAccessError>
where Self: Sized,

使用当前有效的本地运行时(runtime)准备计时等待,正时长首次登记直达其本地定时任务队列。 当前本地环境不可用时同步返回错误;计时及取消(cancellation)沿用 timeout。

Source

fn timeout_on_local<F>( _future: F, _duration: Duration, ) -> Result<TimeoutOn<Self::Timer, F>, LocalRuntimeAccessError>
where F: Future, Self: Sized,

通过当前有效的本地运行时组合业务异步计算(Future)与超时(timeout)。 业务优先,只有挂起才登记计时;业务不增加 Send、Sync、Unpin 或 ’static 约束。

Source

fn sleep_local( _duration: Duration, ) -> Result<Sleep<Self::Timer>, LocalRuntimeAccessError>
where Self: Sized,

使用当前有效的本地运行时准备短时等待,时长与完成语义沿用 sleep。

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

§

impl<C, E, I, T> RuntimeTime for RuntimeHandle<C, E, I, T>

§

impl<M, C, P, H, E, I, T> RuntimeTime for ConfiguredRuntime<M, C, P, H, E, I, T>