Parcourir la source

Make sure that autosens has a profile to work with

The Swift version of autosens expects to have a profile object, so if
you start with oref-swift from the start the current version will
throw an exception on autosens since there is no profile, and the
algorithm will never make progress.

This change swaps the order of autosens and profile creation. Profile
creation doesn't depend on autosens, so this change is safe and
enables systems set up as oref-swift from the start run.

Note: There was a tiny amount of parallelism in the previous version,
but not enough to justify so I removed it to make the code more
straightforward.
Sam King il y a 2 semaines
Parent
commit
134a9eebe4
1 fichiers modifiés avec 5 ajouts et 6 suppressions
  1. 5 6
      Trio/Sources/APS/APSManager.swift

+ 5 - 6
Trio/Sources/APS/APSManager.swift

@@ -468,14 +468,13 @@ final class BaseAPSManager: APSManager, Injectable {
         do {
         do {
             let now = Date()
             let now = Date()
 
 
-            // Parallelize the fetches using async let
-            async let currentTemp = fetchCurrentTempBasal(date: now)
-            async let autosenseResult = autosense()
-
-            _ = try await autosenseResult
+            // put profile creation up front since autosens needs it
             try await openAPS.createProfiles(useSwiftOref: settings.useSwiftOref)
             try await openAPS.createProfiles(useSwiftOref: settings.useSwiftOref)
+            let currentTemp = try await fetchCurrentTempBasal(date: now)
+            _ = try await autosense()
+
             let determination = try await openAPS.determineBasal(
             let determination = try await openAPS.determineBasal(
-                currentTemp: await currentTemp,
+                currentTemp: currentTemp,
                 shouldSmoothGlucose: settingsManager.settings.smoothGlucose,
                 shouldSmoothGlucose: settingsManager.settings.smoothGlucose,
                 useSwiftOref: settings.useSwiftOref,
                 useSwiftOref: settings.useSwiftOref,
                 clock: now
                 clock: now