mirror of
https://github.com/romanz/electrs.git
synced 2026-08-14 12:42:52 +02:00
16 lines
479 B
Rust
16 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")
|
|
}
|