Updated the function that checks for the sim running and how we stream data

This commit is contained in:
2026-09-17 23:01:50 +01:00
parent 7675c7e34a
commit 1b9a5173b6
2 changed files with 35 additions and 34 deletions
+15 -12
View File
@@ -126,6 +126,10 @@ func (i *IRacing) stream(ctx context.Context) {
i.data.InitialTime = time.Now()
go func() {
// Put this into the configuration file
consecutiveTimeouts := 0
maxTimeouts := 30
dataEvTimeout := 100
for {
// Explicitly intercept cancellation
select {
@@ -134,17 +138,8 @@ func (i *IRacing) stream(ctx context.Context) {
default:
}
// TODO: fix this logic
// We start by checking if we do or do not have data available
// if !i.isDataAvailable() {
// i.logger.Info("isDataAvailable check failed. Cancelling stream...")
// i.streamCancel()
// }
select {
case <-ctx.Done():
return
case <-i.ticker.C:
if i.SDK.CheckForDataEvent(time.Duration(dataEvTimeout) * time.Millisecond) {
consecutiveTimeouts = 0
i.readData()
// Publish data
@@ -153,6 +148,15 @@ func (i *IRacing) stream(ctx context.Context) {
default:
// skip this data, don't allow publishers to lag behind
}
} else {
consecutiveTimeouts++
if consecutiveTimeouts >= maxTimeouts {
i.logger.Info("Telemetry stream stalled")
if i.streamCancel != nil {
i.streamCancel()
}
return
}
}
}
}()
@@ -175,7 +179,6 @@ func (i *IRacing) readData() {
}
// Set up virtual binds
i.logger.Debug("Entering virtual binds loop")
for _, vBind := range i.data.VirtualBinds {
vBind.Process(i.data)
}