From 7e1303cb9cfd5a09883bdc05385937c7d43ef356 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Thu, 6 Mar 2025 14:25:38 -0900 Subject: [PATCH] check on bug --- derby/derby.go | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/derby/derby.go b/derby/derby.go index 8970c9f..13105bf 100644 --- a/derby/derby.go +++ b/derby/derby.go @@ -179,29 +179,11 @@ func (dc *DerbyClock) readLoop() { continue } - // If we hit a newline, this might be the end of all results - if b[0] == '\n' { - // Check if we should consider the race complete - dc.mu.Lock() - if dc.status == StatusRunning { - dc.status = StatusFinished - dc.mu.Unlock() - - // Send race complete event - dc.eventChan <- Event{Type: EventRaceComplete} - } else { - dc.mu.Unlock() - } - - // Clear the buffer after a newline - buffer = buffer[:0] - } - // Add the byte to our buffer buffer = append(buffer, b[0]) // Check for race start signal "C\r\n" - if len(buffer) >= 3 && string(buffer[len(buffer)-3:]) == "C\r\n" { + if b[0] == 'C' { dc.mu.Lock() dc.status = StatusRunning dc.mu.Unlock() @@ -212,11 +194,7 @@ func (dc *DerbyClock) readLoop() { // Clear the buffer buffer = buffer[:0] continue - } - - // Check for lane result pattern (n=t.ttttc) - // We need to look for an equals sign followed by digits, a period, more digits, and a finish character - if b[0] == ' ' { + } else if b[0] == ' ' { // These characters could indicate a complete result or a separator // Try to extract a result from the buffer dc.mu.Lock() @@ -231,8 +209,22 @@ func (dc *DerbyClock) readLoop() { // Clear the buffer after a result is extracted buffer = buffer[:0] dc.mu.Unlock() - } + } else if b[0] == '\n' { + // Check if we should consider the race complete + dc.mu.Lock() + if dc.status == StatusRunning { + dc.status = StatusFinished + dc.mu.Unlock() + + // Send race complete event + dc.eventChan <- Event{Type: EventRaceComplete} + } else { + dc.mu.Unlock() + } + // Clear the buffer after a newline + buffer = buffer[:0] + } } } }