refactor: handle closing NsdManager service discovery if already stopped

This commit is contained in:
andrekir 2024-02-25 08:29:39 -03:00
parent 55ae55a817
commit 6a0d9b523b

View file

@ -56,7 +56,13 @@ private fun NsdManager.discoverServices(
trySend(emptyList()) // Emit an initial empty list
discoverServices(serviceType, protocolType, discoveryListener)
awaitClose { stopServiceDiscovery(discoveryListener) }
awaitClose {
try {
stopServiceDiscovery(discoveryListener)
} catch (ex: IllegalArgumentException) {
// ignore if discovery is already stopped
}
}
}
private suspend fun NsdManager.resolveService(