Skip to main content

TimerWithThread

Struct TimerWithThread 

Source
pub struct TimerWithThread<I, O>
where I: Hash + Clone + Eq + Ord, O: State<Id = I>,
{ /* private fields */ }
Expand description

A timer implementation that uses its own thread.

This instance is essentially the owning handle. Non-owning references can be created with [TimerWithThread::timer_ref] and are always cloneable.

Implementations§

Source§

impl<I, O> TimerWithThread<I, O>
where I: Hash + Clone + Eq + Ord + Debug + Send + 'static, O: State<Id = I> + Debug + Send + 'static,

Source

pub fn new( max_wait_time: Duration, ) -> Result<TimerWithThread<I, O>, ThreadTimerError>

Create a new timer with its own thread.

max_wait_time is the maximum time we wait until we check the clock again, in case it jumped (e.g. after sleep or due to a timezone change).

Source

pub fn new_with_clock<C>( clock: C, max_wait_time: Duration, ) -> Result<TimerWithThread<I, O>, ThreadTimerError>
where C: Clock,

Create a new timer with its own thread using a custom clock.

This is mostly meant for testing, but can also be used to supply other clock sources than [SystemTime].

max_wait_time is the maximum time we wait until we check the clock again, in case it jumped (e.g. after sleep or due to a timezone change).

Source

pub fn timer_ref(&self) -> TimerRef<I, O>

Returns a shareable reference to this timer.

Source

pub fn shutdown(self) -> Result<(), ThreadTimerError>

Shut this timer down and wait for the thread to join.

Source

pub fn shutdown_async(&self) -> Result<(), ThreadTimerError>

Same as shutdown, but doesn’t wait for the thread to join.

Source§

impl TimerWithThread<Uuid, ClosureState<Uuid>>

Source

pub fn for_uuid_closures( max_wait_time: Duration, ) -> Result<Self, ThreadTimerError>

Available on crate feature uuid only.

Create a UUID-based timer using closure states.

Trait Implementations§

Source§

impl<I, O> Debug for TimerWithThread<I, O>
where I: Hash + Clone + Eq + Ord, O: State<Id = I>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I, O> Default for TimerWithThread<I, O>
where I: Hash + Clone + Eq + Ord + Debug + Send + 'static, O: State<Id = I> + Debug + Send + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<I, O> Freeze for TimerWithThread<I, O>

§

impl<I, O> !RefUnwindSafe for TimerWithThread<I, O>

§

impl<I, O> Send for TimerWithThread<I, O>
where I: Send, O: Send,

§

impl<I, O> Sync for TimerWithThread<I, O>
where I: Send, O: Send,

§

impl<I, O> Unpin for TimerWithThread<I, O>

§

impl<I, O> !UnwindSafe for TimerWithThread<I, O>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.