mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00: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:
parent
431c7bc3b2
commit
34225cdfe3
1 changed files with 6 additions and 2 deletions
|
|
@ -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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue