refactor: restrict visibility of wait_for_data/is_connected/frame and fully transition API to read_frame()#11
Conversation
… fully transition API to read_frame()
There was a problem hiding this comment.
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.
| 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, | ||
| } | ||
| } |
There was a problem hiding this comment.
Checking self.is_connected() before sleeping prevents the thread from sleeping unnecessarily when the simulator has already disconnected.
| 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.
No description provided.