diff --git a/src/util.rs b/src/util.rs index 2f9c20f..15522b5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -5,6 +5,7 @@ use std::collections::HashMap; use std::fmt; use std::iter::FromIterator; use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender}; +use std::thread; use time; pub type Bytes = Vec; @@ -228,3 +229,15 @@ impl Channel { &self.rx } } + +pub fn spawn_thread(name: &str, f: F) -> thread::JoinHandle +where + F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, +{ + thread::Builder::new() + .name(name.to_owned()) + .spawn(f) + .unwrap() +}