1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 18:10:51 +01:00

Add helper function for spawning named threads

This commit is contained in:
Roman Zeyde 2018-06-14 11:51:58 +03:00
parent 7908877000
commit 6a5dd18349
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -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()
}