reorder checking for race end.

main
DustyP 9 months ago
parent e0c682b744
commit 1374d2c179

@ -179,6 +179,24 @@ func (dc *DerbyClock) readLoop() {
continue 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 // Add the byte to our buffer
buffer = append(buffer, b[0]) buffer = append(buffer, b[0])
@ -198,7 +216,7 @@ func (dc *DerbyClock) readLoop() {
// Check for lane result pattern (n=t.ttttc) // 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 // We need to look for an equals sign followed by digits, a period, more digits, and a finish character
if b[0] == ' ' || b[0] == '\r' { if b[0] == ' ' {
// These characters could indicate a complete result or a separator // These characters could indicate a complete result or a separator
// Try to extract a result from the buffer // Try to extract a result from the buffer
result := dc.tryExtractResult(buffer) result := dc.tryExtractResult(buffer)
@ -213,23 +231,6 @@ func (dc *DerbyClock) readLoop() {
buffer = buffer[:0] 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]
}
} }
} }
} }

Loading…
Cancel
Save