diff --git a/app/src/main/java/com/onthelevel/OnTheLevelApp.kt b/app/src/main/java/com/onthelevel/OnTheLevelApp.kt index 038ea21..50aad57 100644 --- a/app/src/main/java/com/onthelevel/OnTheLevelApp.kt +++ b/app/src/main/java/com/onthelevel/OnTheLevelApp.kt @@ -22,8 +22,13 @@ class AppContainer(context: Context) { * Outlives any single screen. Used for durable fire-and-forget persistence * (e.g. saving a calibration): a screen-scoped coroutine would be cancelled if * the user leaves the moment the write is launched. + * + * Main.immediate (not Default) so writes launched from UI callbacks enqueue in + * call order — two fast conflicting writes (recalibrate then Reset) then reach + * DataStore deterministically. Only lightweight persistence runs here; DataStore + * still performs the actual IO on its own dispatcher. */ - val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) + val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) val sensorSource: SensorSource by lazy { AndroidSensorSource(appContext) } val settings: SettingsRepository by lazy { SettingsRepository(appContext) }