Coroutine timeout

pull/32/head
Administrator 5 years ago
parent 929255a171
commit 0e2636068a
  1. 2
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  2. 7
      app/src/main/java/io/legado/app/ui/search/SearchViewModel.kt

@ -1,6 +1,5 @@
package io.legado.app.help.coroutine package io.legado.app.help.coroutine
import android.util.Log
import kotlinx.coroutines.* import kotlinx.coroutines.*
class Coroutine<T>(scope: CoroutineScope, private val domain: suspend CoroutineScope.() -> T) { class Coroutine<T>(scope: CoroutineScope, private val domain: suspend CoroutineScope.() -> T) {
@ -75,7 +74,6 @@ class Coroutine<T>(scope: CoroutineScope, private val domain: suspend CoroutineS
private suspend fun executeDomain(domain: suspend CoroutineScope.() -> T): T? { private suspend fun executeDomain(domain: suspend CoroutineScope.() -> T): T? {
return withContext(Dispatchers.IO) { return withContext(Dispatchers.IO) {
Log.e("TAG!", "executeDomain")
domain() domain()
} }
} }

@ -5,12 +5,7 @@ import android.util.Log
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.api.CommonHttpApi
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.http.HttpHelper
import kotlinx.coroutines.delay
import kotlinx.coroutines.withTimeout
import org.jetbrains.anko.error
class SearchViewModel(application: Application) : BaseViewModel(application) { class SearchViewModel(application: Application) : BaseViewModel(application) {
@ -18,7 +13,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
fun search(start: (() -> Unit)? = null, finally: (() -> Unit)? = null) { fun search(start: (() -> Unit)? = null, finally: (() -> Unit)? = null) {
execute { execute {
// val response: String = HttpHelper.getApiService<CommonHttpApi>( // val response: String = HttpHelper.getApiService<CommonHttpApi>(
// "http://www.baidu.com" // "http://www.baidu.com"
// ).get("http://www.baidu.com").await() // ).get("http://www.baidu.com").await()
// //

Loading…
Cancel
Save