Skip to main content

BlockingSleeper

Struct BlockingSleeper 

Source
pub struct BlockingSleeper { /* private fields */ }
Expand description

Adapts any Timer into synchronous blocking sleep operations.

This type owns no clock or scheduling policy of its own. It composes a shared timer and blocks only the calling thread while polling the timer’s future. Clones share that same timer.

§Progress

The timer backend must still make progress after the calling thread parks. StdTimer has its own worker. A ManualTimer requires another thread or controller to advance its clock. A TokioTimer requires its retained runtime to remain alive and be driven independently. Blocking the sole driver thread of a current-thread Tokio runtime while waiting on that same runtime’s timer prevents the deadline from completing.

Implementations§

Source§

impl BlockingSleeper

Source

pub const fn new(timer: Arc<dyn Timer>) -> Self

Creates a blocking adapter over a shared timer.

§Parameters
  • timer - Timer used for every blocking deadline. Its backend must progress independently while the calling thread is parked.
§Returns

A cloneable blocking sleeper composing timer.

Source

pub fn timer(&self) -> &dyn Timer

Returns the timer composed by this adapter.

§Returns

The timer used to register blocking sleeps.

Source

pub fn sleep_until(&self, deadline: MonotonicInstant) -> Result<(), TimeError>

Blocks the current thread until an absolute deadline is reached.

§Parameters
  • deadline - Deadline in the composed timer’s clock domain.
§Returns

Ok(()) after the deadline future completes.

§Errors

Returns any error produced while registering or completing the deadline.

§Panics

Panics when the composed timer panics during registration or its returned future panics while being polled.

§Blocking

Parks the calling thread while the composed timer is pending. The timer backend must be driven independently during that interval.

Source

pub fn sleep_for(&self, duration: Duration) -> Result<(), TimeError>

Blocks the current thread for a relative duration.

The timer fixes the absolute deadline before this method begins polling and parking.

§Parameters
  • duration - Duration measured by the composed timer’s clock.
§Returns

Ok(()) after the deadline future completes.

§Errors

Returns deadline overflow, registration failure, or a backend failure reported while waiting.

§Panics

Panics when the composed timer panics during registration or its returned future panics while being polled.

§Blocking

Parks the calling thread while the composed timer is pending. The timer backend must be driven independently during that interval.

Trait Implementations§

Source§

impl Clone for BlockingSleeper

Source§

fn clone(&self) -> BlockingSleeper

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockingSleeper

Source§

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

Formats this adapter without requiring the timer trait object to be debug-formattable.

§Parameters
  • formatter - Destination formatter.
§Returns

Ok(()) when formatting succeeds.

§Errors

Returns std::fmt::Error when the destination rejects output.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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.