Skip to content

refactor: restrict visibility of wait_for_data/is_connected/frame and fully transition API to read_frame()#11

Merged
mvoof merged 2 commits into
mainfrom
feat/read-result
Jun 15, 2026
Merged

refactor: restrict visibility of wait_for_data/is_connected/frame and fully transition API to read_frame()#11
mvoof merged 2 commits into
mainfrom
feat/read-result

Conversation

@mvoof

@mvoof mvoof commented Jun 14, 2026

Copy link
Copy Markdown
Owner

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a unified ReadResult enum and read_frame / read_frame_into methods across different simulator connections (iRacing, AC Evo, and LMU) to simplify and standardize the frame reading loop. It internalizes the previous wait_for_data, is_connected, and direct frame methods, updating all examples and documentation accordingly. The review feedback suggests optimizing the new read_frame and read_frame_into implementations across all three simulators by checking is_connected() early, which avoids unnecessary sleeping or blocking when the simulator has already disconnected.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/ac_evo/connection.rs
Comment thread src/iracing/connection.rs
Comment thread src/lmu/connection.rs
Comment thread src/lmu/connection.rs
Comment on lines +268 to +281
pub fn read_frame_into(&self, out: &mut LmuFrame, timeout_ms: u32) -> ReadResult<()> {
if timeout_ms > 0 {
std::thread::sleep(std::time::Duration::from_millis(timeout_ms as u64));
}

if !self.is_connected() {
return ReadResult::Disconnected;
}

match self.frame_into(out) {
Ok(()) => ReadResult::Frame(()),
Err(_) => ReadResult::Disconnected,
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Checking self.is_connected() before sleeping prevents the thread from sleeping unnecessarily when the simulator has already disconnected.

Suggested change
pub fn read_frame_into(&self, out: &mut LmuFrame, timeout_ms: u32) -> ReadResult<()> {
if timeout_ms > 0 {
std::thread::sleep(std::time::Duration::from_millis(timeout_ms as u64));
}
if !self.is_connected() {
return ReadResult::Disconnected;
}
match self.frame_into(out) {
Ok(()) => ReadResult::Frame(()),
Err(_) => ReadResult::Disconnected,
}
}
pub fn read_frame_into(&self, out: &mut LmuFrame, timeout_ms: u32) -> ReadResult<()> {
if !self.is_connected() {
return ReadResult::Disconnected;
}
if timeout_ms > 0 {
std::thread::sleep(std::time::Duration::from_millis(timeout_ms as u64));
}
if !self.is_connected() {
return ReadResult::Disconnected;
}
match self.frame_into(out) {
Ok(()) => ReadResult::Frame(()),
Err(_) => ReadResult::Disconnected,
}
}

Check is_connected() before sleeping in AcEvoConnection::read_frame,
LmuConnection::read_frame, and LmuConnection::read_frame_into to avoid
blocking for the full timeout_ms when the sim is already gone.
@mvoof mvoof merged commit 7c63b92 into main Jun 15, 2026
1 check passed
@mvoof mvoof deleted the feat/read-result branch June 15, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant