pub struct TimerArgs {
pub timestamp: DInstant,
pub deadline: Deadline,
/* private fields */
}
Expand description
Arguments for an on_interval
handler.
Note the timer can be stopped using the handlers unsubscribe
,
and once handlers stop the timer automatically.
The field values are about the specific call to handler that received the args, the methods on the other hand
are connected with the timer by a weak reference and always show the up-to-date state of the timer.
For synchronous handlers this does not matter, but for async handlers this means that the values can be
different after each .await
. This can be useful to for example, disable the timer until the async task finishes
but it can also be surprising.
Fields§
§timestamp: DInstant
When the handler was called.
deadline: Deadline
Expected deadline, is less-or-equal to the timestamp
.
Implementations§
source§impl TimerArgs
impl TimerArgs
sourcepub fn interval(&self) -> Duration
pub fn interval(&self) -> Duration
The timer interval. Enabled handlers are called every time this interval elapses.
sourcepub fn set_interval(&self, new_interval: Duration)
pub fn set_interval(&self, new_interval: Duration)
Set the interval
.
Note that this method does not awake the app, so if this is called from outside the app thread it will only apply on the next app update.
sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
If the timer is ticking.
sourcepub fn pause(&self)
pub fn pause(&self)
Disable the timer, this causes the timer to stop ticking until play
is called.
sourcepub fn play(&self, reset: bool)
pub fn play(&self, reset: bool)
Enable the timer, this causes it to start ticking again.
If reset
is true
the last timestamp
is set to now.
sourcepub fn last_timestamp(&self) -> DInstant
pub fn last_timestamp(&self) -> DInstant
The timestamp of the last update. This can be different from timestamp
after the first .await
in async handlers of if called from a different thread.
sourcepub fn next_deadline(&self) -> Deadline
pub fn next_deadline(&self) -> Deadline
The next timer deadline.
This is last_timestamp
plus interval
.
sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
If the timer was stopped while the handler was running after it started handling.
Note the timer can be stopped from the inside of the handler using the handlers
unsubscribe
, and once handlers stop the timer automatically.
Outside of the handler the TimerHandle
can be used to stop the timer at any time, even from another thread.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TimerArgs
impl !RefUnwindSafe for TimerArgs
impl Send for TimerArgs
impl Sync for TimerArgs
impl Unpin for TimerArgs
impl !UnwindSafe for TimerArgs
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more