chore: Use repeatOnLifecycle for lifecycle-aware coroutine launch (#3952)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-12-10 10:15:25 -06:00 committed by GitHub
parent 431c7bc3b2
commit 34225cdfe3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,7 @@ package org.meshtastic.core.data.repository
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@ -29,6 +30,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.meshtastic.core.data.datasource.NodeInfoReadDataSource
import org.meshtastic.core.data.datasource.NodeInfoWriteDataSource
@ -56,8 +58,10 @@ constructor(
) {
init {
// Backfill denormalized name columns for existing nodes on startup
processLifecycle.coroutineScope.launchWhenCreated {
withContext(dispatchers.io) { nodeInfoWriteDataSource.backfillDenormalizedNames() }
processLifecycle.coroutineScope.launch {
processLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
withContext(dispatchers.io) { nodeInfoWriteDataSource.backfillDenormalizedNames() }
}
}
}