Scheduler

Trait Scheduler 

Source
pub trait Scheduler:
    Clone
    + NecessarySendSync
    + 'static {
    // Required methods
    fn schedule_future(
        &self,
        future: impl Future<Output = ()> + NecessarySendSync + 'static,
    ) -> impl Disposable + NecessarySendSync + 'static;
    fn sleep(
        &self,
        duration: Duration,
    ) -> impl Future + NecessarySendSync + 'static;

    // Provided methods
    fn schedule(
        &self,
        task: impl FnOnce() + NecessarySendSync + 'static,
        delay: Option<Duration>,
    ) -> impl Disposable + NecessarySendSync + 'static { ... }
    fn schedule_recursively(
        &self,
        task: impl FnMut(usize) -> RecursionAction + NecessarySendSync + 'static,
        delay: Option<Duration>,
    ) -> impl Disposable + NecessarySendSync + 'static { ... }
    fn schedule_periodically(
        &self,
        task: impl FnMut(usize) -> bool + NecessarySendSync + 'static,
        period: Duration,
        delay: Option<Duration>,
    ) -> impl Disposable + NecessarySendSync + 'static { ... }
}
Expand description

Core abstraction for driving asynchronous work across runtimes. See https://reactivex.io/documentation/scheduler.html This is why the task must be ’static: https://stackoverflow.com/a/65287449/9315497

Required Methods§

Source

fn schedule_future( &self, future: impl Future<Output = ()> + NecessarySendSync + 'static, ) -> impl Disposable + NecessarySendSync + 'static

Source

fn sleep(&self, duration: Duration) -> impl Future + NecessarySendSync + 'static

Provided Methods§

Source

fn schedule( &self, task: impl FnOnce() + NecessarySendSync + 'static, delay: Option<Duration>, ) -> impl Disposable + NecessarySendSync + 'static

Source

fn schedule_recursively( &self, task: impl FnMut(usize) -> RecursionAction + NecessarySendSync + 'static, delay: Option<Duration>, ) -> impl Disposable + NecessarySendSync + 'static

Source

fn schedule_periodically( &self, task: impl FnMut(usize) -> bool + NecessarySendSync + 'static, period: Duration, delay: Option<Duration>, ) -> impl Disposable + NecessarySendSync + '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§