bsp_server/
io_thread.rs

1use std::{io, thread};
2
3pub struct IoThreads {
4    pub reader: thread::JoinHandle<io::Result<()>>,
5    pub writer: thread::JoinHandle<io::Result<()>>,
6}
7
8impl IoThreads {
9    // Creates an IoThreads
10    pub(crate) fn new(
11        reader: thread::JoinHandle<io::Result<()>>,
12        writer: thread::JoinHandle<io::Result<()>>,
13    ) -> IoThreads {
14        IoThreads { reader, writer }
15    }
16
17    pub fn join(self) -> io::Result<()> {
18        match self.reader.join() {
19            Ok(r) => r?,
20            Err(err) => {
21                println!("reader panicked!");
22                std::panic::panic_any(err)
23            }
24        }
25        match self.writer.join() {
26            Ok(r) => r,
27            Err(err) => {
28                println!("writer panicked!");
29                std::panic::panic_any(err);
30            }
31        }
32    }
33}