Simplify run_block slightly (#2830)

* Simplify run_block slightly

* Add early return on C-c
This commit is contained in:
Maximilian Roos 2020-12-30 15:37:07 -08:00 committed by GitHub
parent 79476a5cb2
commit 69b3be61a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,6 @@ pub async fn run_block(
inp,
)
.await?;
loop {
match output_stream.try_next().await {
Ok(Some(ReturnSuccess::Value(Value {
value: UntaggedValue::Error(e),
@ -52,7 +51,7 @@ pub async fn run_block(
return Err(err.clone());
}
if ctx.ctrl_c.load(Ordering::SeqCst) {
break;
return Ok(InputStream::empty());
}
}
Ok(None) => {
@ -60,13 +59,11 @@ pub async fn run_block(
ctx.clear_errors();
return Err(err.clone());
}
break;
}
Err(e) => return Err(e),
}
}
}
}
Err(e) => {
return Err(e);
}
@ -78,7 +75,6 @@ pub async fn run_block(
Ok(inp) => {
let mut output_stream = inp.to_output_stream();
loop {
match output_stream.try_next().await {
Ok(Some(ReturnSuccess::Value(Value {
value: UntaggedValue::Error(e),
@ -90,7 +86,12 @@ pub async fn run_block(
return Err(err.clone());
}
if ctx.ctrl_c.load(Ordering::SeqCst) {
break;
// This early return doesn't return the result
// we have so far, but breaking out of this loop
// causes lifetime issues. A future contribution
// could attempt to return the current output.
// https://github.com/nushell/nushell/pull/2830#discussion_r550319687
return Ok(InputStream::empty());
}
}
Ok(None) => {
@ -98,12 +99,10 @@ pub async fn run_block(
ctx.clear_errors();
return Err(err.clone());
}
break;
}
Err(e) => return Err(e),
}
}
}
Err(e) => {
return Err(e);
}