diff options
author | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-05-08 18:10:46 +0200 |
---|---|---|
committer | Lizzy Fleckenstein <eliasfleckenstein@web.de> | 2023-05-08 18:21:19 +0200 |
commit | cf2d1870a2585069a1286ecca77109a12ca4dd47 (patch) | |
tree | 99872daaa9d4d2b467e03b2d01a3e06f4816f5db /src | |
parent | b6d021cded621e75ca66e83ebbec161130eb9f73 (diff) | |
download | mt_client-cf2d1870a2585069a1286ecca77109a12ca4dd47.tar.xz |
Handle net thread panic
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 8 | ||||
-rw-r--r-- | src/net.rs | 1 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index f517ee2..0d83ae5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,12 +35,16 @@ fn main() { .build() .unwrap(); - let net_thread = runtime.spawn(net::run(event_loop_proxy, net_rx)); + let net_thread = runtime.spawn(net::run(event_loop_proxy.clone(), net_rx)); + let net_recover_thread = std::thread::spawn(move || { + runtime.block_on(net_thread).ok(); + event_loop_proxy.send_event(GfxEvent::Close).ok(); // tell graphics to shut down + }); // graphics code is pseudo async: the winit event loop is blocking // so we can't really use async capabilities futures::executor::block_on(gfx::run(event_loop, net_tx)); // wait for net to finish - runtime.block_on(net_thread).unwrap(); + net_recover_thread.join().unwrap(); } @@ -117,7 +117,6 @@ pub(crate) async fn run( } } - conn.events.send_event(GfxEvent::Close).ok(); // TODO: make sure to send this on panic worker_thread.await.unwrap(); } |