Skip to main content

TaskDispatch

Trait TaskDispatch 

pub trait TaskDispatch {
    type Notifier: TaskNotifier;

    // Required methods
    fn create_with_config<F, M>(
        &self,
        future: F,
        config: TaskConfig<M>,
    ) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output, M>), CreateError<F, M>>
       where F: Future + Send + 'static,
             <F as Future>::Output: Send + 'static,
             M: Send + Sync + 'static;
    fn submit(&self, task: UnsubmittedTask) -> Result<(), SubmitError>;

    // Provided methods
    fn create<F>(
        &self,
        future: F,
    ) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output>), CreateError<F, ()>>
       where F: Future + Send + 'static,
             <F as Future>::Output: Send + 'static { ... }
    fn spawn_with_config<F, M>(
        &self,
        future: F,
        config: TaskConfig<M>,
    ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output, M>, SpawnError<F, Self::Notifier, M>>
       where F: Future + Send + 'static,
             <F as Future>::Output: Send + 'static,
             M: Send + Sync + 'static { ... }
    fn spawn<F>(
        &self,
        future: F,
    ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output>, SpawnError<F, Self::Notifier>>
       where F: Future + Send + 'static,
             <F as Future>::Output: Send + 'static { ... }
}

Required Associated Types§

Required Methods§

Source

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

创建原服务的可跨线程任务(Task)并保留配置;不提交、不接纳、不轮询(poll)。失败返还原Future和配置。

Source

fn submit(&self, task: UnsubmittedTask) -> Result<(), SubmitError>

向创建它的原服务提交唯一原值;明确拒绝返还原持有及原因,不取消、不改线程归属。

Provided Methods§

Source

fn create<F>( &self, future: F, ) -> Result<(UnsubmittedTask, TaskHandle<Self::Notifier, <F as Future>::Output>), CreateError<F, ()>>
where F: Future + Send + 'static, <F as Future>::Output: Send + 'static,

使用默认配置创建;返回唯一待提交值与结果句柄(handle),不隐式派发。

Source

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

组合一次创建与提交;错误按创建/提交阶段保留对应原值,成功不表示已经执行。

Source

fn spawn<F>( &self, future: F, ) -> Result<TaskHandle<Self::Notifier, <F as Future>::Output>, SpawnError<F, Self::Notifier>>
where F: Future + Send + 'static, <F as Future>::Output: Send + 'static,

使用默认配置组合创建与提交;输入及输出只要求可跨线程转交(Send),不要求Sync或Unpin。

Examples found in repository?
examples/runtime_bounds.rs (lines 56-59)
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> TaskDispatch for RuntimeHandle<C, E, I, T>

§

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