Making sure Cancellation of coroutines stops long processes.

This commit is contained in:
Vitor Pamplona
2024-01-30 17:27:48 -05:00
parent 6b60b1434f
commit eae07e2fe0
52 changed files with 141 additions and 7 deletions
@@ -33,6 +33,7 @@ import com.google.mlkit.nl.translate.TranslatorOptions
import com.linkedin.urls.detection.UrlDetector
import com.linkedin.urls.detection.UrlDetectorOptions
import com.vitorpamplona.amethyst.service.checkNotInMainThread
import kotlinx.coroutines.CancellationException
import java.util.concurrent.Executors
import java.util.regex.Pattern
@@ -161,7 +162,8 @@ object LanguageTranslatorService {
val short = "A$counter"
counter++
returningList.put(short, tag)
} catch (_: Exception) {
} catch (e: Exception) {
if (e is CancellationException) throw e
}
}
return returningList
@@ -177,7 +179,8 @@ object LanguageTranslatorService {
val short = "A$counter"
counter++
returningList.put(short, lnInvoice)
} catch (_: Exception) {
} catch (e: Exception) {
if (e is CancellationException) throw e
}
}
return returningList
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.service.notifications
import android.util.Log
import com.google.firebase.messaging.FirebaseMessaging
import com.vitorpamplona.amethyst.AccountInfo
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.tasks.await
@@ -38,6 +39,7 @@ object PushNotificationUtils {
try {
RegisterAccounts(accounts).go(FirebaseMessaging.getInstance().token.await())
} catch (e: Exception) {
if (e is CancellationException) throw e
Log.e("Firebase token", "failed to get firebase token", e)
}
}