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
impl BlockingSleeper
Sourcepub fn sleep_until(&self, deadline: MonotonicInstant) -> Result<(), TimeError>
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.
Sourcepub fn sleep_for(&self, duration: Duration) -> Result<(), TimeError>
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
impl Clone for BlockingSleeper
Source§fn clone(&self) -> BlockingSleeper
fn clone(&self) -> BlockingSleeper
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockingSleeper
impl Debug for BlockingSleeper
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
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.