using runblocking for MAL intercept

since scope launches will run async
This commit is contained in:
Jay 2020-06-06 16:28:34 -04:00
parent 8ce1d94fd2
commit 06192419cb

View File

@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.track.myanimelist
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Request import okhttp3.Request
import okhttp3.RequestBody import okhttp3.RequestBody
@ -17,14 +17,14 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList) : Interceptor
val scope = CoroutineScope(Job() + Dispatchers.Main) val scope = CoroutineScope(Job() + Dispatchers.Main)
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
scope.launch { runBlocking {
myanimelist.ensureLoggedIn() myanimelist.ensureLoggedIn()
} }
val request = chain.request() val request = chain.request()
var response = chain.proceed(updateRequest(request)) var response = chain.proceed(updateRequest(request))
if (response.code == 400) { if (response.code == 400) {
scope.launch { runBlocking {
myanimelist.refreshLogin() myanimelist.refreshLogin()
} }
response.close() response.close()