Add named thread for pty reader

This commit is contained in:
Joe Wilm 2016-06-07 21:11:23 -07:00
parent 5e920b893a
commit 06451fbab1
No known key found for this signature in database
GPG Key ID: 39B57C6972F518DA
2 changed files with 15 additions and 1 deletions

View File

@ -28,6 +28,7 @@ mod meter;
mod tty;
mod ansi;
mod term;
mod util;
use std::sync::mpsc::TryRecvError;
use std::collections::HashMap;
@ -42,6 +43,7 @@ use text::FontDesc;
use grid::Grid;
use term::Term;
use meter::Meter;
use util::thread;
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default)]
pub struct Rgb {
@ -128,7 +130,7 @@ fn main() {
}
let (chars_tx, chars_rx) = ::std::sync::mpsc::channel();
::std::thread::spawn(move || {
thread::spawn_named("TTY Reader", move || {
for c in reader.chars() {
let c = c.unwrap();
chars_tx.send(c).unwrap();

12
src/util.rs Normal file
View File

@ -0,0 +1,12 @@
/// Threading utilities
pub mod thread {
/// Like `thread::spawn`, but with a `name` argument
pub fn spawn_named<F, T, S>(name: S, f: F) -> ::std::thread::JoinHandle<T>
where F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static,
S: Into<String>
{
::std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works")
}
}