pub struct Events;Implementations§
Source§impl Events
impl Events
Sourcepub fn emit<T: Serialize + ?Sized>(
&self,
name: &str,
payload: &T,
to: Target,
) -> Result<()>
pub fn emit<T: Serialize + ?Sized>( &self, name: &str, payload: &T, to: Target, ) -> Result<()>
Examples found in repository?
More examples
examples/heartbeat_daemon.rs (line 42)
33 async fn run(&self, cx: Context) {
34 let _ = cx.events().on("heartbeat.ping");
35 // Answer pings beside the heartbeat loop.
36 let events = cx.clone();
37 cx.spawn(async move {
38 loop {
39 if let Event::Plugin { name, .. } = events.next_event().await
40 && name == "heartbeat.ping"
41 {
42 let _ = events.events().emit("heartbeat.pong", &(), Target::All);
43 }
44 }
45 });
46 loop {
47 self.beats.set(self.beats.get() + 1);
48 let _ = cx.live().publish("heartbeat.beat", &self.beats.get());
49 cx.sleep(30_000).await;
50 }
51 }Sourcepub fn on(&self, pattern: &str) -> Result<()>
pub fn on(&self, pattern: &str) -> Result<()>
Listens to events whose names match pattern (git.*).
Examples found in repository?
More examples
examples/heartbeat_daemon.rs (line 34)
33 async fn run(&self, cx: Context) {
34 let _ = cx.events().on("heartbeat.ping");
35 // Answer pings beside the heartbeat loop.
36 let events = cx.clone();
37 cx.spawn(async move {
38 loop {
39 if let Event::Plugin { name, .. } = events.next_event().await
40 && name == "heartbeat.ping"
41 {
42 let _ = events.events().emit("heartbeat.pong", &(), Target::All);
43 }
44 }
45 });
46 loop {
47 self.beats.set(self.beats.get() + 1);
48 let _ = cx.live().publish("heartbeat.beat", &self.beats.get());
49 cx.sleep(30_000).await;
50 }
51 }pub fn off(&self, pattern: &str) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Events
impl RefUnwindSafe for Events
impl Send for Events
impl Sync for Events
impl Unpin for Events
impl UnsafeUnpin for Events
impl UnwindSafe for Events
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