Skip to main content

SingleThreadScheduledExecutorService

Struct SingleThreadScheduledExecutorService 

Source
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

Source

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.

Source

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.

Source

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.

Source

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 Drop for SingleThreadScheduledExecutorService

Source§

fn drop(&mut self)

Requests graceful shutdown when the service handle is dropped.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl ExecutorService for SingleThreadScheduledExecutorService

Source§

fn submit<T, E>(&self, task: T) -> Result<(), SubmissionError>
where T: Runnable<E> + Send + 'static, E: Send + 'static,

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>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

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>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

Accepts a callable for immediate execution with a scheduled task handle.

Source§

fn shutdown(&self)

Requests graceful shutdown and drains accepted scheduled work.

Source§

fn stop(&self) -> StopReport

Requests immediate shutdown and cancels tasks that have not started.

Source§

fn lifecycle(&self) -> ExecutorServiceLifecycle

Returns the current lifecycle state.

Source§

fn is_not_running(&self) -> bool

Returns whether shutdown has started.

Source§

fn is_terminated(&self) -> bool

Returns whether the scheduler thread has exited.

Source§

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

Result handle returned for an accepted callable task.
Source§

type TrackedHandle<R, E> = ScheduledTaskHandle<R, E> where R: Send + 'static, E: Send + 'static

Tracked handle returned for accepted tasks that expose status.
Source§

fn submit_tracked<T, E>( &self, task: T, ) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
where T: Runnable<E> + Send + 'static, E: Send + 'static,

Submits a runnable task and returns a tracked handle. Read more
Source§

fn is_running(&self) -> bool

Returns whether the service accepts new tasks. Read more
Source§

fn is_shutting_down(&self) -> bool

Returns whether graceful shutdown is in progress. Read more
Source§

fn is_stopping(&self) -> bool

Returns whether abrupt stop is in progress. Read more
Source§

impl ScheduledExecutorService for SingleThreadScheduledExecutorService

Source§

fn schedule_callable_at<C, R, E>( &self, instant: Instant, task: C, ) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

Schedules a callable task to start at a monotonic instant.

Source§

fn schedule<T, E>( &self, delay: Duration, task: T, ) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
where T: Runnable<E> + Send + 'static, E: Send + 'static,

Schedules a runnable task to start after the supplied delay. Read more
Source§

fn schedule_callable<C, R, E>( &self, delay: Duration, task: C, ) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

Schedules a callable task to start after the supplied delay. Read more
Source§

fn schedule_at<T, E>( &self, instant: Instant, task: T, ) -> Result<Self::TrackedHandle<(), E>, SubmissionError>
where T: Runnable<E> + Send + 'static, E: Send + 'static,

Schedules a runnable task to start at a monotonic instant. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.