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