Trait AsyncRuntimeExt

Source
pub trait AsyncRuntimeExt<O: Default + 'static = ()> {
    // Required methods
    fn spawn_with_context<F, C>(
        &self,
        task_id: TaskId,
        future: F,
        context: C,
    ) -> Result<()>
       where F: Future<Output = O> + Send + 'static,
             C: 'static;
    fn spawn_timing_with_context<F, C>(
        &self,
        task_id: TaskId,
        future: F,
        context: C,
        time: usize,
    ) -> Result<()>
       where F: Future<Output = O> + Send + 'static,
             C: Send + 'static;
    fn block_on<F>(&self, future: F) -> Result<F::Output>
       where F: Future + Send + 'static,
             <F as Future>::Output: Default + Send + 'static;
}
Expand description

异步运行时扩展

Required Methods§

Source

fn spawn_with_context<F, C>( &self, task_id: TaskId, future: F, context: C, ) -> Result<()>
where F: Future<Output = O> + Send + 'static, C: 'static,

派发一个指定的异步任务到异步运行时,并指定异步任务的初始化上下文

Source

fn spawn_timing_with_context<F, C>( &self, task_id: TaskId, future: F, context: C, time: usize, ) -> Result<()>
where F: Future<Output = O> + Send + 'static, C: Send + 'static,

派发一个在指定时间后执行的异步任务到异步运行时,并指定异步任务的初始化上下文,时间单位ms

Source

fn block_on<F>(&self, future: F) -> Result<F::Output>
where F: Future + Send + 'static, <F as Future>::Output: Default + Send + 'static,

立即创建一个指定任务池的异步运行时,并执行指定的异步任务,阻塞当前线程,等待异步任务完成后返回

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<O: Default + 'static, P: AsyncTaskPoolExt<O> + AsyncTaskPool<O, Pool = P>> AsyncRuntimeExt<O> for MultiTaskRuntime<O, P>

Source§

impl<O: Default + 'static, P: AsyncTaskPoolExt<O> + AsyncTaskPool<O, Pool = P>> AsyncRuntimeExt<O> for SingleTaskRuntime<O, P>

Source§

impl<O: Default + 'static, P: AsyncTaskPoolExt<O> + AsyncTaskPool<O, Pool = P>> AsyncRuntimeExt<O> for WorkerRuntime<O, P>