Skip to main content

DelayedTaskScheduler

Struct DelayedTaskScheduler 

Source
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

Source

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.

Source

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.

Source

pub fn schedule<F>( &self, delay: Duration, task: F, ) -> Result<DelayedTaskHandle, SubmissionError>
where F: FnOnce() + Send + 'static,

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.

Source

pub fn shutdown(&self)

Requests graceful shutdown.

Source

pub fn stop(&self) -> StopReport

Requests immediate shutdown and cancels pending delayed tasks.

§Returns

Count-based shutdown report.

Source

pub fn lifecycle(&self) -> ExecutorServiceLifecycle

Returns the current lifecycle state.

§Returns

ExecutorServiceLifecycle::Terminated after the scheduler thread has exited, otherwise the stored lifecycle state.

Source

pub fn is_running(&self) -> bool

Returns whether this scheduler still accepts delayed tasks.

§Returns

true only while the lifecycle is ExecutorServiceLifecycle::Running.

Source

pub fn is_shutting_down(&self) -> bool

Returns whether graceful shutdown is in progress.

§Returns

true only while the lifecycle is ExecutorServiceLifecycle::ShuttingDown.

Source

pub fn is_stopping(&self) -> bool

Returns whether abrupt stop is in progress.

§Returns

true only while the lifecycle is ExecutorServiceLifecycle::Stopping.

Source

pub fn is_not_running(&self) -> bool

Returns whether shutdown has started.

§Returns

true if this scheduler rejects new tasks.

Source

pub fn is_terminated(&self) -> bool

Returns whether the scheduler thread has exited.

§Returns

true after shutdown and termination.

Source

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.

Source

pub fn wait_termination(&self)

Blocks until the scheduler thread has terminated.

Trait Implementations§

Source§

impl Drop for DelayedTaskScheduler

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.