Skip to main content

LocalTaskDispatch

Trait LocalTaskDispatch 

Source
pub trait LocalTaskDispatch: TaskDispatch {
    // Required methods
    fn create_local_with_config<F, M>(
        future: F,
        config: TaskConfig<M>,
    ) -> RawResult<(UnsubmittedTask, TaskHandle<Self::Notifier, F::Output, M, LocalOutput>), CreateError<F, M>>
       where F: Future + 'static,
             F::Output: 'static,
             M: Send + Sync + 'static;
    fn submit_local(task: UnsubmittedTask) -> RawResult<(), SubmitError>;

    // Provided methods
    fn create_local<F>(
        future: F,
    ) -> RawResult<(UnsubmittedTask, TaskHandle<Self::Notifier, F::Output, (), LocalOutput>), CreateError<F, ()>>
       where F: Future + 'static,
             F::Output: 'static { ... }
    fn spawn_local_with_config<F, M>(
        future: F,
        config: TaskConfig<M>,
    ) -> RawResult<TaskHandle<Self::Notifier, F::Output, M, LocalOutput>, SpawnError<F, Self::Notifier, M, LocalOutput>>
       where F: Future + 'static,
             F::Output: 'static,
             M: Send + Sync + 'static { ... }
    fn spawn_local<F>(
        future: F,
    ) -> RawResult<TaskHandle<Self::Notifier, F::Output, (), LocalOutput>, SpawnError<F, Self::Notifier, (), LocalOutput>>
       where F: Future + 'static,
             F::Output: 'static { ... }
}
Expand description

静态本地入口;真实当前权限由实现核对,不要求Future/Output为Send或Sync。

Required Methods§

Source

fn create_local_with_config<F, M>( future: F, config: TaskConfig<M>, ) -> RawResult<(UnsubmittedTask, TaskHandle<Self::Notifier, F::Output, M, LocalOutput>), CreateError<F, M>>
where F: Future + 'static, F::Output: 'static, M: Send + Sync + 'static,

通过当前有效本地权限创建;原Future与输出保持原线程清理,不要求Send/Sync/Unpin。失败返还原输入。

Source

fn submit_local(task: UnsubmittedTask) -> RawResult<(), SubmitError>

仅在原所属线程(owner thread)的有效本地范围首次提交;错误返还同一待提交值。

Provided Methods§

Source

fn create_local<F>( future: F, ) -> RawResult<(UnsubmittedTask, TaskHandle<Self::Notifier, F::Output, (), LocalOutput>), CreateError<F, ()>>
where F: Future + 'static, F::Output: 'static,

使用默认配置进行本地创建;无合法当前环境时明确失败,不猜测目标。

Source

fn spawn_local_with_config<F, M>( future: F, config: TaskConfig<M>, ) -> RawResult<TaskHandle<Self::Notifier, F::Output, M, LocalOutput>, SpawnError<F, Self::Notifier, M, LocalOutput>>
where F: Future + 'static, F::Output: 'static, M: Send + Sync + 'static,

组合本地创建与本地提交;不把结果变为可跨线程,不将拒绝当成取消。

Source

fn spawn_local<F>( future: F, ) -> RawResult<TaskHandle<Self::Notifier, F::Output, (), LocalOutput>, SpawnError<F, Self::Notifier, (), LocalOutput>>
where F: Future + 'static, F::Output: 'static,

默认配置的本地快速派发(local dispatch);不创建新线程,不内联轮询(poll)。

Examples found in repository?
examples/api_bounds.rs (lines 14-17)
12fn local_non_send<R: Runtime>() {
13    let value = Rc::new(Cell::new(1));
14    let _result = R::spawn_local(async move {
15        value.set(2);
16        value
17    });
18    let value = Rc::new(Cell::new(3));
19    let _timed = R::spawn_timing_local(async move { value }, Duration::from_millis(2));
20}

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§