#![doc(html_root_url = "https://movie.pzmarzly.pl")]
use std::thread::JoinHandle;
pub trait JoinableHandle {
fn join(self);
}
impl JoinableHandle for JoinHandle<()> {
#[allow(unused_must_use)]
fn join(self) {
self.join();
}
}
pub struct Handle<T: JoinableHandle, TX> {
pub join_handle: T,
pub tx: std::sync::mpsc::Sender<TX>,
pub kill: std::sync::mpsc::Sender<()>,
}
impl<T: JoinableHandle, TX> Handle<T, TX> {
pub fn send(&self, msg: TX) {
self.tx.send(msg).unwrap();
}
#[allow(unused_must_use)]
pub fn stop(self) {
self.kill.send(());
self.join_handle.join();
}
}