|
@@ -33,9 +33,14 @@ extension Home.StateModel {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Update forecast data and UI on the main thread
|
|
// Update forecast data and UI on the main thread
|
|
|
|
|
+ //
|
|
|
|
|
+ // Runs inside `forecastUpdateTask`; cancellation is checked after every suspension
|
|
|
|
|
+ // point so a superseded run cannot overwrite fresher results.
|
|
|
@MainActor func updateForecastData() async {
|
|
@MainActor func updateForecastData() async {
|
|
|
let forecastDataIDs = await preprocessForecastData()
|
|
let forecastDataIDs = await preprocessForecastData()
|
|
|
|
|
|
|
|
|
|
+ guard !Task.isCancelled else { return }
|
|
|
|
|
+
|
|
|
var allForecastValues = [[Int]]()
|
|
var allForecastValues = [[Int]]()
|
|
|
var preprocessedData = [(id: UUID, forecast: Forecast, forecastValue: ForecastValue)]()
|
|
var preprocessedData = [(id: UUID, forecast: Forecast, forecastValue: ForecastValue)]()
|
|
|
|
|
|
|
@@ -97,6 +102,8 @@ extension Home.StateModel {
|
|
|
return (minForecast, maxForecast)
|
|
return (minForecast, maxForecast)
|
|
|
}.value
|
|
}.value
|
|
|
|
|
|
|
|
|
|
+ guard !Task.isCancelled else { return }
|
|
|
|
|
+
|
|
|
minForecast = minResult
|
|
minForecast = minResult
|
|
|
maxForecast = maxResult
|
|
maxForecast = maxResult
|
|
|
}
|
|
}
|