Skip to content

Commit 2b81dca

Browse files
committed
fix: respect interrupt signals in .cat -f streaming
Use recv_timeout with 100ms polling to check for interrupt signals, allowing Ctrl-C to terminate long-running .cat -f streams.
1 parent 93dd1af commit 2b81dca

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/nu/commands/cat_stream_command.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use nu_engine::CallExt;
22
use nu_protocol::engine::{Call, Command, EngineState, Stack};
33
use nu_protocol::{
4-
Category, ListStream, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
4+
Category, ListStream, PipelineData, ShellError, Signals, Signature, SyntaxShape, Type, Value,
55
};
66
use std::time::Duration;
77

@@ -143,8 +143,24 @@ impl Command for CatStreamCommand {
143143
});
144144
});
145145

146-
// Create ListStream from channel
147-
let stream = ListStream::new(std::iter::from_fn(move || rx.recv().ok()), span, signals);
146+
// Create ListStream from channel with signal-aware polling
147+
let stream = ListStream::new(
148+
std::iter::from_fn(move || {
149+
use std::sync::mpsc::RecvTimeoutError;
150+
loop {
151+
if signals.interrupted() {
152+
return None;
153+
}
154+
match rx.recv_timeout(Duration::from_millis(100)) {
155+
Ok(value) => return Some(value),
156+
Err(RecvTimeoutError::Timeout) => continue,
157+
Err(RecvTimeoutError::Disconnected) => return None,
158+
}
159+
}
160+
}),
161+
span,
162+
Signals::empty(),
163+
);
148164

149165
Ok(PipelineData::ListStream(stream, None))
150166
}

0 commit comments

Comments
 (0)