mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Add helper function for spawning named threads
This commit is contained in:
parent
7908877000
commit
6a5dd18349
13
src/util.rs
13
src/util.rs
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender};
|
use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender};
|
||||||
|
use std::thread;
|
||||||
use time;
|
use time;
|
||||||
|
|
||||||
pub type Bytes = Vec<u8>;
|
pub type Bytes = Vec<u8>;
|
||||||
@ -228,3 +229,15 @@ impl<T> Channel<T> {
|
|||||||
&self.rx
|
&self.rx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn spawn_thread<F, T>(name: &str, f: F) -> thread::JoinHandle<T>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> T,
|
||||||
|
F: Send + 'static,
|
||||||
|
T: Send + 'static,
|
||||||
|
{
|
||||||
|
thread::Builder::new()
|
||||||
|
.name(name.to_owned())
|
||||||
|
.spawn(f)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user