Name threads (#7879)

I noticed that [it's pretty easy to name threads in
Rust](https://doc.rust-lang.org/std/thread/#naming-threads). We might as
well do this; it's a nice quality of life improvement when you're
profiling something and the developers took the time to give threads
names.

Also added/cleaned up some comments while I was in the area.
This commit is contained in:
Reilly Wood
2023-01-28 21:40:52 +01:00
committed by GitHub
parent e616b2e247
commit f4d7d19370
5 changed files with 116 additions and 82 deletions

View File

@ -8,6 +8,7 @@ use nu_protocol::{
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
use std::thread;
use crate::progress_bar;
@ -85,13 +86,17 @@ impl Command for Save {
// delegate a thread to redirect stderr to result.
let handler = stderr.map(|stderr_stream| match stderr_file {
Some(stderr_file) => std::thread::spawn(move || {
stream_to_file(stderr_stream, stderr_file, span, progress)
}),
None => std::thread::spawn(move || {
let _ = stderr_stream.into_bytes();
Ok(PipelineData::empty())
}),
Some(stderr_file) => thread::Builder::new()
.name("stderr redirector".to_string())
.spawn(move || stream_to_file(stderr_stream, stderr_file, span, progress))
.expect("Failed to create thread"),
None => thread::Builder::new()
.name("stderr redirector".to_string())
.spawn(move || {
let _ = stderr_stream.into_bytes();
Ok(PipelineData::empty())
})
.expect("Failed to create thread"),
});
let res = stream_to_file(stream, file, span, progress);