fix: ensure try_read always reads at least once (#10)

This commit is contained in:
Austin Schey
2025-07-19 15:38:47 -07:00
committed by GitHub
parent 3f861342e0
commit 5d82d07f17
2 changed files with 10 additions and 2 deletions

View File

@@ -82,7 +82,7 @@ impl EventSource for UnixEventSource {
fn try_read(&mut self, timeout: Option<Duration>) -> io::Result<Option<Event>> {
let timeout = PollTimeout::new(timeout);
while timeout.leftover().map_or(true, |t| !t.is_zero()) {
loop {
if let Some(event) = self.parser.pop() {
return Ok(Some(event));
}
@@ -136,6 +136,10 @@ impl EventSource for UnixEventSource {
"Poll operation was woken up",
));
}
if timeout.leftover().is_some_and(|t| t.is_zero()) {
break;
}
}
Ok(None)

View File

@@ -41,7 +41,7 @@ impl EventSource for WindowsEventSource {
let timeout = PollTimeout::new(timeout);
while timeout.leftover().map_or(true, |t| !t.is_zero()) {
loop {
if let Some(event) = self.parser.pop() {
return Ok(Some(event));
}
@@ -81,6 +81,10 @@ impl EventSource for WindowsEventSource {
let records = self.input.read_console_input(pending)?;
self.parser.decode_input_records(&records);
if timeout.leftover().is_some_and(|t| t.is_zero()) {
break;
}
}
Ok(None)