1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00
electrs/src/thread.rs
Christopher Bergqvist cd348e72de Warn on attempt to connect over SSL
Also output underlying errors when a thread fails.
2021-12-02 17:30:04 +02:00

17 lines
479 B
Rust

use anyhow::Result;
pub(crate) fn spawn<F>(name: &'static str, f: F) -> std::thread::JoinHandle<()>
where
F: 'static + Send + FnOnce() -> Result<()>,
{
std::thread::Builder::new()
.name(name.to_owned())
.spawn(move || {
if let Err(e) = f() {
warn!("{} thread failed: {}", name, e);
e.chain().skip(1).for_each(|e| warn!("because: {}", e));
}
})
.expect("failed to spawn a thread")
}