I'm writing a Gtk-rs application. I have a background thread sending events to the main Gtk thread through a MPSC channel. What should I do with unrecoverable errors inside this background thread?
I don't want to handle them (To panic! or Not to panic!).
Currently, the thread will panic, but the main application won't stop. I'd like the whole application to crash with the error.
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
// Spawn the thread and move the sender in there
thread::spawn(move || {
loop {
let msg = do_work().unwrap();
sender.send(msg).unwrap();
}
});
receiver.attach(None, move |msg| {
...
glib::Continue(true)
});
- I don't want to send a Result through the channel because it wouldn't work for panics in called functions.
- Joining the thread would solve the problem, but I don't think I can do it with Gtk-rs since it is blocking.
This question is similar to How can I cause a panic on a thread to immediately end the main thread?, but I wonder there is a better solution for Gtk-rs.