From 4c63c0150178f9be2f53e499aaf125e24cfe7805 Mon Sep 17 00:00:00 2001 From: Jobobby04 Date: Fri, 24 Sep 2021 13:06:10 -0400 Subject: [PATCH] Cleanup and reduce the amount of time it waits for logouts --- .../exh/md/network/MangaDexLoginHelper.kt | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/exh/md/network/MangaDexLoginHelper.kt b/app/src/main/java/exh/md/network/MangaDexLoginHelper.kt index 24bef4c3d..ba88c2f0b 100644 --- a/app/src/main/java/exh/md/network/MangaDexLoginHelper.kt +++ b/app/src/main/java/exh/md/network/MangaDexLoginHelper.kt @@ -11,10 +11,7 @@ import exh.md.service.MangaDexAuthService import exh.md.utils.MdUtil import exh.util.seconds import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.Job -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch +import kotlinx.coroutines.withTimeoutOrNull import kotlinx.serialization.encodeToString class MangaDexLoginHelper(val authServiceLazy: Lazy, val preferences: PreferencesHelper, val mdList: MdList) { @@ -76,20 +73,8 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy, val pr suspend fun logout() { return withIOContext { - try { - coroutineScope { - var delayJob: Job? = null - val loginJob = launch { - authService.logout() - delayJob?.cancel() - } - delayJob = launch { - delay(30.seconds) - loginJob.cancel() - } - } - } catch (e: Exception) { - if (e is CancellationException) throw e + withTimeoutOrNull(10.seconds) { + authService.logout() } } }