use crate::exec::Event;
use std::fmt;
use std::sync::mpsc;
pub struct Sender<M>(pub(super) mpsc::Sender<Event<M>>);
impl<M> Clone for Sender<M> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<M> fmt::Debug for Sender<M> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Sender(..)")
}
}
impl<M> Sender<M> {
pub fn send(&self, msg: M) -> bool {
self.0.send(Event::Send(msg)).is_ok()
}
pub fn quit(&self) {
let _ = self.0.send(Event::Quit);
}
pub fn kill(&self) {
let _ = self.0.send(Event::Kill);
}
}