pub struct DelayedTaskScheduler { /* private fields */ }Expand description
Single-threaded scheduler for cancellable delayed tasks.
The scheduler only owns delay timing. Scheduled closures should stay small; submit longer work to an executor service from the closure.
Implementations§
Source§impl DelayedTaskScheduler
impl DelayedTaskScheduler
Sourcepub fn new(thread_name: &str) -> Result<Self, ExecutorServiceBuilderError>
pub fn new(thread_name: &str) -> Result<Self, ExecutorServiceBuilderError>
Starts a new delayed task scheduler.
§Parameters
thread_name- Name for the scheduler thread.
§Returns
A started delayed task scheduler.
§Errors
Returns ExecutorServiceBuilderError::SpawnWorker if the scheduler thread
cannot be created.
Sourcepub fn with_stack_size(
thread_name: &str,
stack_size: Option<usize>,
) -> Result<Self, ExecutorServiceBuilderError>
pub fn with_stack_size( thread_name: &str, stack_size: Option<usize>, ) -> Result<Self, ExecutorServiceBuilderError>
Starts a new delayed task scheduler with an optional thread stack size.
§Parameters
thread_name- Name for the scheduler thread.stack_size- Optional stack size for the scheduler thread.
§Returns
A started delayed task scheduler.
§Errors
Returns ExecutorServiceBuilderError::SpawnWorker if the scheduler thread
cannot be created.
Sourcepub fn schedule<F>(
&self,
delay: Duration,
task: F,
) -> Result<DelayedTaskHandle, SubmissionError>
pub fn schedule<F>( &self, delay: Duration, task: F, ) -> Result<DelayedTaskHandle, SubmissionError>
Schedules a task to run after the given delay.
§Parameters
delay- Minimum delay before the task becomes runnable.task- Action to run on the scheduler thread after the delay.
§Returns
A handle that can cancel the task before it starts.
§Errors
Returns SubmissionError::Shutdown after shutdown starts.
Sourcepub fn stop(&self) -> StopReport
pub fn stop(&self) -> StopReport
Requests immediate shutdown and cancels pending delayed tasks.
§Returns
Count-based shutdown report.
Sourcepub fn lifecycle(&self) -> ExecutorServiceLifecycle
pub fn lifecycle(&self) -> ExecutorServiceLifecycle
Returns the current lifecycle state.
§Returns
ExecutorServiceLifecycle::Terminated after the scheduler thread has
exited, otherwise the stored lifecycle state.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether this scheduler still accepts delayed tasks.
§Returns
true only while the lifecycle is ExecutorServiceLifecycle::Running.
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Returns whether graceful shutdown is in progress.
§Returns
true only while the lifecycle is
ExecutorServiceLifecycle::ShuttingDown.
Sourcepub fn is_stopping(&self) -> bool
pub fn is_stopping(&self) -> bool
Returns whether abrupt stop is in progress.
§Returns
true only while the lifecycle is ExecutorServiceLifecycle::Stopping.
Sourcepub fn is_not_running(&self) -> bool
pub fn is_not_running(&self) -> bool
Sourcepub fn is_terminated(&self) -> bool
pub fn is_terminated(&self) -> bool
Sourcepub fn queued_count(&self) -> usize
pub fn queued_count(&self) -> usize
Returns the number of pending delayed tasks.
§Returns
Number of accepted delayed tasks that have not started or been cancelled.
Sourcepub fn wait_termination(&self)
pub fn wait_termination(&self)
Blocks until the scheduler thread has terminated.