diff --git a/derby/derby.go b/derby/derby.go index 530421e..2e32a3b 100644 --- a/derby/derby.go +++ b/derby/derby.go @@ -198,7 +198,7 @@ func (dc *DerbyClock) readLoop() { // 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] == ' ' || b[0] == '\n' { + if b[0] == ' ' || b[0] == '\r' { // These characters could indicate a complete result or a separator // Try to extract a result from the buffer result := dc.tryExtractResult(buffer) @@ -208,25 +208,27 @@ func (dc *DerbyClock) readLoop() { Type: EventLaneFinish, Result: result, } + } + // Clear the buffer after a result is extracted + buffer = buffer[:0] + } - // 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] - } + // 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] } } }