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

@ -5,6 +5,7 @@ use crate::{
};
use nu_utils::{stderr_write_all_and_flush, stdout_write_all_and_flush};
use std::sync::{atomic::AtomicBool, Arc};
use std::thread;
const LINE_ENDING_PATTERN: &[char] = &['\r', '\n'];
@ -726,8 +727,11 @@ pub fn print_if_stream(
exit_code: Option<ListStream>,
) -> Result<i64, ShellError> {
// NOTE: currently we don't need anything from stderr
// so directly consumes `stderr_stream` to make sure that everything is done.
std::thread::spawn(move || stderr_stream.map(|x| x.into_bytes()));
// so we just consume and throw away `stderr_stream` to make sure the pipe doesn't fill up
thread::Builder::new()
.name("stderr consumer".to_string())
.spawn(move || stderr_stream.map(|x| x.into_bytes()))
.expect("could not create thread");
if let Some(stream) = stream {
for s in stream {
let s_live = s?;