forked from extern/nushell
Use threads to avoid blocking reads/writes in externals. (#1440)
In particular, one thing that we can't (properly) do before this commit is consuming an infinite input stream. For example: ``` yes | grep y | head -n10 ``` will give 10 "y"s in most shells, but blocks indefinitely in nu. This PR resolves that by doing blocking I/O in threads, and reducing the `await` calls we currently have in our pipeline code.
This commit is contained in:
@ -102,7 +102,7 @@ mod it_evaluation {
|
||||
}
|
||||
|
||||
mod stdin_evaluation {
|
||||
use super::nu_error;
|
||||
use super::{nu, nu_error};
|
||||
use nu_test_support::pipeline;
|
||||
|
||||
#[test]
|
||||
@ -117,6 +117,21 @@ mod stdin_evaluation {
|
||||
|
||||
assert_eq!(stderr, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_block_indefinitely() {
|
||||
let stdout = nu!(
|
||||
cwd: ".",
|
||||
pipeline(r#"
|
||||
iecho yes
|
||||
| chop
|
||||
| chop
|
||||
| first 1
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(stdout, "y");
|
||||
}
|
||||
}
|
||||
|
||||
mod external_words {
|
||||
|
Reference in New Issue
Block a user