check if there are any results before finishing race.

main
DustyP 9 months ago
parent 7e1303cb9c
commit bcb9c77e6b

@ -161,7 +161,7 @@ func (dc *DerbyClock) Results() []*Result {
// readLoop continuously reads from the serial port
func (dc *DerbyClock) readLoop() {
buffer := make([]byte, 0, 256)
results := make([]*Result, 0, 10)
for {
select {
case <-dc.stopReading:
@ -206,18 +206,20 @@ func (dc *DerbyClock) readLoop() {
Result: result,
}
}
results = append(results, result)
// 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 {
if dc.status == StatusRunning && results != nil {
dc.status = StatusFinished
dc.mu.Unlock()
// Send race complete event
dc.eventChan <- Event{Type: EventRaceComplete}
results = nil
} else {
dc.mu.Unlock()
}

Loading…
Cancel
Save