pub struct AtomicTimer { /* private fields */ }Expand description
Atomic timer
Implementations§
Source§impl AtomicTimer
impl AtomicTimer
Sourcepub fn new(duration: Duration) -> Self
pub fn new(duration: Duration) -> Self
Create a new atomic timer
§Panics
Panics if the duration is too large (in nanos greater than i64::MAX)
Sourcepub fn new_expired(duration: Duration) -> Self
pub fn new_expired(duration: Duration) -> Self
Create a new atomic timer expired
§Panics
Panics if the duration is too large (in nanos greater than i64::MAX)
Sourcepub fn permit_handle_expiration(&self) -> bool
pub fn permit_handle_expiration(&self) -> bool
Similar to reset if expired but does not reset the timer. As the timer is checked for expiration, a tiny datarace may occur despite it passes the tests well. As soon as the timer is reset with any method, the flag is reset as well. If used in multi-threaded environment, “true” is returned to a single worker only. After, the flag is reset.
Sourcepub fn set_duration(&self, duration: Duration)
pub fn set_duration(&self, duration: Duration)
Sourcepub fn expire_now(&self)
pub fn expire_now(&self)
Focibly expire the timer
Sourcepub fn reset_if_expired(&self) -> bool
pub fn reset_if_expired(&self) -> bool
Reset the timer if it has expired, returns true if reset. If used in multi-threaded environment, “true” is returned to a single worker only.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Get the elapsed time
In case if negative elapsed, returns Duration::ZERO