AsyncRuntime

Trait AsyncRuntime 

Source
pub trait AsyncRuntime<O: Default + 'static = ()>:
    Clone
    + Send
    + Sync
    + 'static {
    type Pool: AsyncTaskPoolExt<O> + AsyncTaskPool<O, Pool = Self::Pool>;

Show 25 methods // Required methods fn shared_pool(&self) -> Arc<Self::Pool>; fn get_id(&self) -> usize; fn wait_len(&self) -> usize; fn len(&self) -> usize; fn alloc<R: 'static>(&self) -> TaskId; fn spawn<F>(&self, future: F) -> Result<TaskId> where F: Future<Output = O> + 'static; fn spawn_local<F>(&self, future: F) -> Result<TaskId> where F: Future<Output = O> + 'static; fn spawn_priority<F>(&self, priority: usize, future: F) -> Result<TaskId> where F: Future<Output = O> + 'static; fn spawn_yield<F>(&self, future: F) -> Result<TaskId> where F: Future<Output = O> + 'static; fn spawn_timing<F>(&self, future: F, time: usize) -> Result<TaskId> where F: Future<Output = O> + 'static; fn spawn_by_id<F>(&self, task_id: TaskId, future: F) -> Result<()> where F: Future<Output = O> + 'static; fn spawn_local_by_id<F>(&self, task_id: TaskId, future: F) -> Result<()> where F: Future<Output = O> + 'static; fn spawn_priority_by_id<F>( &self, task_id: TaskId, priority: usize, future: F, ) -> Result<()> where F: Future<Output = O> + 'static; fn spawn_yield_by_id<F>(&self, task_id: TaskId, future: F) -> Result<()> where F: Future<Output = O> + 'static; fn spawn_timing_by_id<F>( &self, task_id: TaskId, future: F, time: usize, ) -> Result<()> where F: Future<Output = O> + 'static; fn pending<Output: 'static>( &self, task_id: &TaskId, waker: Waker, ) -> Poll<Output>; fn wakeup<Output: 'static>(&self, task_id: &TaskId); fn wait<V: 'static>(&self) -> AsyncWait<V>; fn wait_any<V: 'static>(&self, capacity: usize) -> AsyncWaitAny<V>; fn wait_any_callback<V: 'static>( &self, capacity: usize, ) -> AsyncWaitAnyCallback<V>; fn map_reduce<V: 'static>(&self, capacity: usize) -> AsyncMapReduce<V>; fn timeout(&self, timeout: usize) -> LocalBoxFuture<'static, ()>; fn yield_now(&self) -> LocalBoxFuture<'static, ()>; fn pipeline<S, SO, F, FO>( &self, input: S, filter: F, ) -> LocalBoxStream<'static, FO> where S: Stream<Item = SO> + 'static, SO: 'static, F: FnMut(SO) -> AsyncPipelineResult<FO> + 'static, FO: 'static; fn close(&self) -> bool;
}
Expand description

顺序执行任务的异步运行时

Required Associated Types§

Source

type Pool: AsyncTaskPoolExt<O> + AsyncTaskPool<O, Pool = Self::Pool>

Required Methods§

Source

fn shared_pool(&self) -> Arc<Self::Pool>

共享运行时内部任务池

Source

fn get_id(&self) -> usize

获取当前异步运行时的唯一id

Source

fn wait_len(&self) -> usize

获取当前异步运行时待处理任务数量

Source

fn len(&self) -> usize

获取当前异步运行时任务数量

Source

fn alloc<R: 'static>(&self) -> TaskId

分配异步任务的唯一id

Source

fn spawn<F>(&self, future: F) -> Result<TaskId>
where F: Future<Output = O> + 'static,

派发一个指定的异步任务到异步运行时

Source

fn spawn_local<F>(&self, future: F) -> Result<TaskId>
where F: Future<Output = O> + 'static,

派发一个异步任务到本地异步运行时,如果本地没有本异步运行时,则会派发到当前运行时中

Source

fn spawn_priority<F>(&self, priority: usize, future: F) -> Result<TaskId>
where F: Future<Output = O> + 'static,

派发一个指定优先级的异步任务到异步运行时

Source

fn spawn_yield<F>(&self, future: F) -> Result<TaskId>
where F: Future<Output = O> + 'static,

派发一个异步任务到异步运行时,并立即让出任务的当前运行

Source

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

派发一个在指定时间后执行的异步任务到异步运行时,时间单位ms

Source

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

派发一个指定任务唯一id的异步任务到异步运行时

Source

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

派发一个指定任务唯一id的异步任务到本地异步运行时,如果本地没有本异步运行时,则会派发到当前运行时中

Source

fn spawn_priority_by_id<F>( &self, task_id: TaskId, priority: usize, future: F, ) -> Result<()>
where F: Future<Output = O> + 'static,

派发一个指定任务唯一id和任务优先级的异步任务到异步运行时

Source

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

派发一个指定任务唯一id的异步任务到异步运行时,并立即让出任务的当前运行

Source

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

派发一个指定任务唯一id和在指定时间后执行的异步任务到异步运行时,时间单位ms

Source

fn pending<Output: 'static>( &self, task_id: &TaskId, waker: Waker, ) -> Poll<Output>

挂起指定唯一id的异步任务

Source

fn wakeup<Output: 'static>(&self, task_id: &TaskId)

唤醒指定唯一id的异步任务

Source

fn wait<V: 'static>(&self) -> AsyncWait<V>

挂起当前异步运行时的当前任务,并在指定的其它运行时上派发一个指定的异步任务,等待其它运行时上的异步任务完成后,唤醒当前运行时的当前任务,并返回其它运行时上的异步任务的值

Source

fn wait_any<V: 'static>(&self, capacity: usize) -> AsyncWaitAny<V>

挂起当前异步运行时的当前任务,并在多个其它运行时上执行多个其它任务,其中任意一个任务完成,则唤醒当前运行时的当前任务,并返回这个已完成任务的值,而其它未完成的任务的值将被忽略

Source

fn wait_any_callback<V: 'static>( &self, capacity: usize, ) -> AsyncWaitAnyCallback<V>

挂起当前异步运行时的当前任务,并在多个其它运行时上执行多个其它任务,任务返回后需要通过用户指定的检查回调进行检查,其中任意一个任务检查通过,则唤醒当前运行时的当前任务,并返回这个已完成任务的值,而其它未完成或未检查通过的任务的值将被忽略,如果所有任务都未检查通过,则强制唤醒当前运行时的当前任务

Source

fn map_reduce<V: 'static>(&self, capacity: usize) -> AsyncMapReduce<V>

构建用于派发多个异步任务到指定运行时的映射归并,需要指定映射归并的容量

Source

fn timeout(&self, timeout: usize) -> LocalBoxFuture<'static, ()>

挂起当前异步运行时的当前任务,等待指定的时间后唤醒当前任务

Source

fn yield_now(&self) -> LocalBoxFuture<'static, ()>

立即让出当前任务的执行

Source

fn pipeline<S, SO, F, FO>( &self, input: S, filter: F, ) -> LocalBoxStream<'static, FO>
where S: Stream<Item = SO> + 'static, SO: 'static, F: FnMut(SO) -> AsyncPipelineResult<FO> + 'static, FO: 'static,

生成一个异步管道,输入指定流,输入流的每个值通过过滤器生成输出流的值

Source

fn close(&self) -> bool

关闭异步运行时,返回请求关闭是否成功

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> AsyncRuntime<O> for LocalTaskRuntime<O>

Source§

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

Source§

type Pool = P

Source§

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

Source§

type Pool = P