pub struct Timer<E: IsEvent<Event = E>> {
pub duration: Duration,
pub on_elapsed: fn(&SenderComponent<E>),
/* private fields */
}Fields§
§duration: Duration§on_elapsed: fn(&SenderComponent<E>)Implementations§
Source§impl<E: IsEvent<Event = E>> Timer<E>
impl<E: IsEvent<Event = E>> Timer<E>
pub fn new(duration: Duration) -> Self
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Schedule the timer to run once.
Examples found in repository?
examples/blinky_without_macro/main.rs (line 41)
30 pub fn on(&mut self, event: &Event) -> Response<Self, Event> {
31 match event {
32
33 Event::OnEntry => {
34 self.light = true;
35 self.counter += 1;
36 if self.counter == 10 {
37 let id = self.get_id().unwrap();
38 self.publish(Event::Detach(id));
39 println!("{}: done", &id);
40 }
41 self.timer.start();
42 Response::Handled
43 }
44
45 Event::TimerElapsed => {
46 Response::Transition(Self::off)
47 }
48
49 _ => Response::Handled
50 }
51 }
52
53 fn off(&mut self, event: &Event) -> Response<Self, Event> {
54 match event {
55
56 Event::OnEntry => {
57 self.light = false;
58 self.timer.start();
59 Response::Handled
60 }
61
62 Event::TimerElapsed => {
63 Response::Transition(Self::on)
64 }
65
66 _ => Response::Handled
67 }
68 }More examples
examples/blinky/main.rs (line 44)
33 pub fn on(&mut self, event: &Event) -> Response<Self, Event> {
34 match event {
35
36 Event::OnEntry => {
37 self.light = true;
38 self.counter += 1;
39 if self.counter == 10 {
40 let id = self.get_id().unwrap();
41 self.publish(Event::Detach(id));
42 println!("{}: done", &id);
43 }
44 self.timer.start();
45 Response::Handled
46 }
47
48 Event::TimerElapsed => {
49 Response::Transition(Self::off)
50 }
51
52 _ => Response::Handled
53
54 }
55 }
56
57 fn off(&mut self, event: &Event) -> Response<Self, Event> {
58 match event {
59
60 Event::OnEntry => {
61 self.light = false;
62 self.timer.start();
63 Response::Handled
64 }
65
66 Event::TimerElapsed => {
67 Response::Transition(Self::on)
68 }
69
70 _ => Response::Handled
71
72 }
73 }Sourcepub fn start_interval(&mut self)
pub fn start_interval(&mut self)
Schedule the timer to run repeatedly.
Trait Implementations§
Source§impl<E: IsEvent<Event = E>> Sender for Timer<E>
impl<E: IsEvent<Event = E>> Sender for Timer<E>
type Event = E
Source§fn get_sender_component_mut(&mut self) -> &mut SenderComponent<Self::Event>
fn get_sender_component_mut(&mut self) -> &mut SenderComponent<Self::Event>
Get a mutable reference to the event sender component.
Source§fn get_sender_component(&self) -> &SenderComponent<Self::Event>
fn get_sender_component(&self) -> &SenderComponent<Self::Event>
Get an immutable reference to the event sender component.
Source§fn set_sender_component(
&mut self,
sender_component: SenderComponent<Self::Event>,
)
fn set_sender_component( &mut self, sender_component: SenderComponent<Self::Event>, )
Set the event sender component.
Source§fn get_sender(&self) -> UnboundedSender<Envelope<Self::Event>>
fn get_sender(&self) -> UnboundedSender<Envelope<Self::Event>>
Get the event sender
Source§fn set_sender(&mut self, sender: UnboundedSender<Envelope<Self::Event>>)
fn set_sender(&mut self, sender: UnboundedSender<Envelope<Self::Event>>)
Set the event sender
Source§fn clear_sender(&mut self)
fn clear_sender(&mut self)
Clear the event sender
Source§fn set_associated_handler_id(&mut self, id: usize)
fn set_associated_handler_id(&mut self, id: usize)
Get associated event handler id, this is the id of the event handler
that owns the event sender.
Source§fn get_associated_handler_id(&self) -> Option<usize>
fn get_associated_handler_id(&self) -> Option<usize>
Get the associated event handler id.
Source§fn clear_associated_handler_id(&mut self)
fn clear_associated_handler_id(&mut self)
Clear the associated event handler id.
Source§fn post_to_self(&self, event: Self::Event)
fn post_to_self(&self, event: Self::Event)
Post an event to event handler to which the event sender is attached.
Auto Trait Implementations§
impl<E> Freeze for Timer<E>
impl<E> !RefUnwindSafe for Timer<E>
impl<E> Send for Timer<E>
impl<E> Sync for Timer<E>
impl<E> Unpin for Timer<E>
impl<E> UnsafeUnpin for Timer<E>
impl<E> !UnwindSafe for Timer<E>
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
Mutably borrows from an owned value. Read more