diff --git a/simple-generated/src/event.rs b/simple-generated/src/event.rs index 175bf64..275b346 100644 --- a/simple-generated/src/event.rs +++ b/simple-generated/src/event.rs @@ -37,14 +37,16 @@ pub enum Event { pub struct EventSource { /// Event receiver channel. receiver: mpsc::Receiver, + /// Handle to the event thread. + _handle: thread::JoinHandle<()>, } impl EventSource { /// Constructs a new instance of [`EventHandler`]. pub fn new(tick_rate: Duration) -> Self { let (sender, receiver) = mpsc::channel(); - thread::spawn(move || event_thread(sender, tick_rate)); - Self { receiver } + let _handle = thread::spawn(move || event_thread(sender, tick_rate)); + Self { receiver, _handle } } /// Receive the next event from the handler thread. diff --git a/simple/template/src/event.rs b/simple/template/src/event.rs index 175bf64..275b346 100644 --- a/simple/template/src/event.rs +++ b/simple/template/src/event.rs @@ -37,14 +37,16 @@ pub enum Event { pub struct EventSource { /// Event receiver channel. receiver: mpsc::Receiver, + /// Handle to the event thread. + _handle: thread::JoinHandle<()>, } impl EventSource { /// Constructs a new instance of [`EventHandler`]. pub fn new(tick_rate: Duration) -> Self { let (sender, receiver) = mpsc::channel(); - thread::spawn(move || event_thread(sender, tick_rate)); - Self { receiver } + let _handle = thread::spawn(move || event_thread(sender, tick_rate)); + Self { receiver, _handle } } /// Receive the next event from the handler thread.