From a808d3bc7726e9c338f4554303972116a240cdba Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Wed, 4 Sep 2024 10:24:07 -0700 Subject: [PATCH] Add the thread handle back as an ignored field --- simple-generated/src/event.rs | 6 ++++-- simple/template/src/event.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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.