pub struct TimerScheduler<Key>{ /* private fields */ }Implementations§
Source§impl<Key> TimerScheduler<Key>
impl<Key> TimerScheduler<Key>
pub fn new(subscriber: OutputPortSubscriber<TimeoutElapsed<Key>>) -> Self
Sourcepub fn start_timer(&mut self, key: Key, timeout: Duration)
pub fn start_timer(&mut self, key: Key, timeout: Duration)
Start a timer that will send msg once to the actor after the given timeout.
Each timer has a key and if a new timer with same key is started the previous is cancelled.
§Warning
It is NOT guaranteed that a message from the previous timer is not received, as it could already be enqueued in the mailbox when the new timer was started.
When the actor receives a timeout message for timer from the scheduler, it should
check if the timer is still active by calling TimerScheduler::intercept_timer_msg
and ignore the message otherwise.
Sourcepub fn is_timer_active(&self, key: &Key) -> bool
pub fn is_timer_active(&self, key: &Key) -> bool
Check if a timer with a given key is active, ie. it hasn’t been canceled nor has it elapsed yet.
Sourcepub fn cancel(&mut self, key: &Key)
pub fn cancel(&mut self, key: &Key)
Cancel a timer with a given key.
If canceling a timer that was already canceled, or key never was used to start a timer this operation will do nothing.
§Warning
It is NOT guaranteed that a message from a canceled timer, including its previous incarnation for the same key, will not be received by the actor, as the message might already be enqueued in the mailbox when cancel is called.
When the actor receives a timeout message for timer from the scheduler, it should
check if the timer is still active by calling TimerScheduler::intercept_timer_msg
and ignore the message otherwise.
Sourcepub fn cancel_all(&mut self)
pub fn cancel_all(&mut self)
Cancel all timers.
Sourcepub fn intercept_timer_msg(
&mut self,
timer_msg: TimeoutElapsed<Key>,
) -> Option<Key>where
Key: Debug,
pub fn intercept_timer_msg(
&mut self,
timer_msg: TimeoutElapsed<Key>,
) -> Option<Key>where
Key: Debug,
Intercepts a timer message and checks the state of the timer associated with the provided timer_msg:
- If the timer message was from canceled timer that was already enqueued in mailbox, returns
None. - If the timer message was from an old timer that was enqueued in mailbox before being canceled, returns
None. - Otherwise it is a valid timer message, returns the associated
Keywrapped inSome.
Trait Implementations§
Auto Trait Implementations§
impl<Key> Freeze for TimerScheduler<Key>
impl<Key> !RefUnwindSafe for TimerScheduler<Key>
impl<Key> Send for TimerScheduler<Key>
impl<Key> Sync for TimerScheduler<Key>where
Key: Sync,
impl<Key> Unpin for TimerScheduler<Key>where
Key: Unpin,
impl<Key> UnsafeUnpin for TimerScheduler<Key>
impl<Key> !UnwindSafe for TimerScheduler<Key>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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