Skip to main content

LocalTaskDispatch

Trait LocalTaskDispatch 

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

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

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

Required Methods§

Source

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

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

Source

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

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

Provided Methods§

Source

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

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

Source

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

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

Source

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

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

Examples found in repository?
examples/runtime_bounds.rs (line 60)
39fn roots(runtime: &ConcurrentRuntime, handle: &Handle) {
40    let value = Rc::new(7);
41    let _: Rc<usize> = runtime.block_on(Borrowed {
42        value: &value,
43        fixed: PhantomPinned,
44    });
45    let _: Rc<usize> = handle.block_on(Borrowed {
46        value: &value,
47        fixed: PhantomPinned,
48    });
49    let _ = runtime.timeout_on(
50        Borrowed {
51            value: &value,
52            fixed: PhantomPinned,
53        },
54        std::time::Duration::from_millis(1),
55    );
56    let _ = handle.spawn(SendNotSync {
57        value: Cell::new(3),
58        fixed: PhantomPinned,
59    });
60    let _ = ConcurrentRuntime::spawn_local(async { Rc::new(1usize) });
61    let _ = ConcurrentRuntime::spawn_local_front(async { Rc::new(2usize) });
62    let _ = SerialRuntime::idle_local(async { Cell::new(4usize) });
63    let _ = handle.wait_one_timeout::<Rc<usize>>(std::time::Duration::from_secs(2));
64}

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> LocalTaskDispatch for RuntimeHandle<C, E, I, T>

§

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