refactor: replace `MutableStateFlow` direct assignment with `update`

pull/821/head
andrekir 2024-01-21 06:36:44 -03:00
rodzic e272d54833
commit 89b508c0cf
1 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ import com.geeksville.mesh.CoroutineDispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -29,9 +30,10 @@ class NetworkRepository @Inject constructor(
init { init {
processLifecycle.coroutineScope.launch(dispatchers.default) { processLifecycle.coroutineScope.launch(dispatchers.default) {
nsdManagerLazy.get()?.let { manager -> val manager = nsdManagerLazy.get() ?: return@launch
manager.discoverServices(SERVICE_TYPE).collectLatest { serviceList -> manager.discoverServices(SERVICE_TYPE).collectLatest { serviceList ->
_resolvedList.value = serviceList _resolvedList.update {
serviceList
.filter { it.serviceName.contains(SERVICE_NAME) } .filter { it.serviceName.contains(SERVICE_NAME) }
.mapNotNull { manager.resolveService(it) } .mapNotNull { manager.resolveService(it) }
} }