mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-09 16:40:20 -04:00
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:
@@ -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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user