diff --git a/derby/derby.go b/derby/derby.go index 13105bf..f753d9e 100644 --- a/derby/derby.go +++ b/derby/derby.go @@ -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() }