pub trait Scheduler {
type D: Disposable + MaybeSend + 'static;
// Required methods
fn spawn_future(
&self,
future: impl Future<Output = ()> + MaybeSend + 'static,
) -> BoundDropDisposal<Self::D>;
fn sleep(
&self,
duration: Duration,
) -> impl Future + MaybeSend + 'static + use<Self>;
// Provided methods
fn schedule(
&self,
task: impl FnOnce() + MaybeSend + 'static,
delay: Option<Duration>,
) -> BoundDropDisposal<Self::D> { ... }
fn schedule_recursively(
&self,
task: impl FnMut(usize) -> RecursionAction + MaybeSend + 'static,
delay: Option<Duration>,
) -> BoundDropDisposal<Self::D>
where Self: Clone + MaybeSend + 'static { ... }
fn schedule_periodically(
&self,
task: impl FnMut(usize) -> bool + MaybeSend + 'static,
period: Duration,
delay: Option<Duration>,
) -> BoundDropDisposal<Self::D>
where Self: Clone + MaybeSend + 'static { ... }
fn schedule_stream<SM>(
&self,
stream: SM,
result_callback: impl FnMut(Option<SM::Item>) -> bool + MaybeSend + 'static,
) -> BoundDropDisposal<Self::D>
where SM: Stream + MaybeSend + '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 Associated Types§
type D: Disposable + MaybeSend + 'static
Required Methods§
fn spawn_future( &self, future: impl Future<Output = ()> + MaybeSend + 'static, ) -> BoundDropDisposal<Self::D>
Provided Methods§
fn schedule( &self, task: impl FnOnce() + MaybeSend + 'static, delay: Option<Duration>, ) -> BoundDropDisposal<Self::D>
Sourcefn schedule_recursively(
&self,
task: impl FnMut(usize) -> RecursionAction + MaybeSend + 'static,
delay: Option<Duration>,
) -> BoundDropDisposal<Self::D>
fn schedule_recursively( &self, task: impl FnMut(usize) -> RecursionAction + MaybeSend + 'static, delay: Option<Duration>, ) -> BoundDropDisposal<Self::D>
Repeatedly runs task until it returns RecursionAction::Stop.
The loop yields to the executor between iterations (even for
ContinueImmediately and already-elapsed ContinueAt instants), so
other tasks can make progress and disposal can take effect.
Sourcefn schedule_periodically(
&self,
task: impl FnMut(usize) -> bool + MaybeSend + 'static,
period: Duration,
delay: Option<Duration>,
) -> BoundDropDisposal<Self::D>
fn schedule_periodically( &self, task: impl FnMut(usize) -> bool + MaybeSend + 'static, period: Duration, delay: Option<Duration>, ) -> BoundDropDisposal<Self::D>
Runs task at a fixed rate anchored to the time of this call
(plus delay), until task returns false.
Fixed-rate semantics: if an execution overruns period, missed runs
are executed back-to-back to catch up — they are never skipped.
§Panics
Panics if period is zero.
Sourcefn schedule_stream<SM>(
&self,
stream: SM,
result_callback: impl FnMut(Option<SM::Item>) -> bool + MaybeSend + 'static,
) -> BoundDropDisposal<Self::D>
fn schedule_stream<SM>( &self, stream: SM, result_callback: impl FnMut(Option<SM::Item>) -> bool + MaybeSend + 'static, ) -> BoundDropDisposal<Self::D>
Drives stream to completion, invoking result_callback with
Some(item) for each element and a final None when the stream ends.
The callback’s answer is what keeps the stream running: returning
false stops polling it right there, and the final None is then
never delivered — the stream is dropped along with the task.
Disposal aborts the task without delivering the final None.
The loop yields to the executor after each element (even when the stream is always ready), so other tasks can make progress and disposal can take effect.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".