pub struct SingleThreadScheduledExecutorService { /* private fields */ }Expand description
Single-threaded scheduled executor service.
The service owns one scheduler OS thread. It accepts tasks into a deadline heap, waits until the earliest task is due, and then runs that task directly on the scheduler thread. Scheduled tasks should therefore stay short; submit heavier work to another executor service from the scheduled task body.
Implementations§
Source§impl SingleThreadScheduledExecutorService
impl SingleThreadScheduledExecutorService
Sourcepub fn new(thread_name: &str) -> Result<Self, ExecutorServiceBuilderError>
pub fn new(thread_name: &str) -> Result<Self, ExecutorServiceBuilderError>
Starts a new single-thread scheduled executor service.
§Parameters
thread_name- Name for the scheduler thread.
§Returns
A started scheduled executor service.
§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 scheduled service with an optional scheduler thread stack size.
§Parameters
thread_name- Name for the scheduler thread.stack_size- Optional stack size for the scheduler thread.
§Returns
A started scheduled executor service.
§Errors
Returns ExecutorServiceBuilderError::SpawnWorker if the scheduler
thread cannot be created.
Sourcepub fn queued_count(&self) -> usize
pub fn queued_count(&self) -> usize
Returns the number of queued scheduled tasks.
§Returns
Number of accepted scheduled tasks that have not started or been cancelled.
Sourcepub fn running_count(&self) -> usize
pub fn running_count(&self) -> usize
Returns the number of currently running tasks.
§Returns
1 when the scheduler thread is running a task, otherwise 0.
Trait Implementations§
Source§impl ExecutorService for SingleThreadScheduledExecutorService
impl ExecutorService for SingleThreadScheduledExecutorService
Source§fn submit<T, E>(&self, task: T) -> Result<(), SubmissionError>
fn submit<T, E>(&self, task: T) -> Result<(), SubmissionError>
Accepts a runnable for immediate execution on the scheduler thread.
Source§fn submit_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::ResultHandle<R, E>, SubmissionError>
fn submit_callable<C, R, E>( &self, task: C, ) -> Result<Self::ResultHandle<R, E>, SubmissionError>
Accepts a callable for immediate execution on the scheduler thread.
Source§fn submit_tracked_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
fn submit_tracked_callable<C, R, E>( &self, task: C, ) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
Accepts a callable for immediate execution with a scheduled task handle.
Source§fn stop(&self) -> StopReport
fn stop(&self) -> StopReport
Requests immediate shutdown and cancels tasks that have not started.
Source§fn lifecycle(&self) -> ExecutorServiceLifecycle
fn lifecycle(&self) -> ExecutorServiceLifecycle
Returns the current lifecycle state.
Source§fn is_not_running(&self) -> bool
fn is_not_running(&self) -> bool
Returns whether shutdown has started.
Source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns whether the scheduler thread has exited.
Source§fn wait_termination(&self)
fn wait_termination(&self)
Blocks until this scheduled service has terminated.
Source§type ResultHandle<R, E> = TaskHandle<R, E>
where
R: Send + 'static,
E: Send + 'static
type ResultHandle<R, E> = TaskHandle<R, E> where R: Send + 'static, E: Send + 'static
Source§type TrackedHandle<R, E> = ScheduledTaskHandle<R, E>
where
R: Send + 'static,
E: Send + 'static
type TrackedHandle<R, E> = ScheduledTaskHandle<R, E> where R: Send + 'static, E: Send + 'static
Source§fn submit_tracked<T, E>(
&self,
task: T,
) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
fn submit_tracked<T, E>( &self, task: T, ) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
Source§fn is_running(&self) -> bool
fn is_running(&self) -> bool
Source§fn is_shutting_down(&self) -> bool
fn is_shutting_down(&self) -> bool
Source§fn is_stopping(&self) -> bool
fn is_stopping(&self) -> bool
Source§impl ScheduledExecutorService for SingleThreadScheduledExecutorService
impl ScheduledExecutorService for SingleThreadScheduledExecutorService
Source§fn schedule_callable_at<C, R, E>(
&self,
instant: Instant,
task: C,
) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
fn schedule_callable_at<C, R, E>( &self, instant: Instant, task: C, ) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
Schedules a callable task to start at a monotonic instant.