Cleanup and reduce the amount of time it waits for logouts

This commit is contained in:
Jobobby04 2021-09-24 13:06:10 -04:00
parent 74ba072e01
commit 4c63c01501

View File

@ -11,10 +11,7 @@ import exh.md.service.MangaDexAuthService
import exh.md.utils.MdUtil import exh.md.utils.MdUtil
import exh.util.seconds import exh.util.seconds
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) { class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val preferences: PreferencesHelper, val mdList: MdList) {
@ -76,20 +73,8 @@ class MangaDexLoginHelper(val authServiceLazy: Lazy<MangaDexAuthService>, val pr
suspend fun logout() { suspend fun logout() {
return withIOContext { return withIOContext {
try { withTimeoutOrNull(10.seconds) {
coroutineScope { authService.logout()
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
} }
} }
} }