Вот как я это делаю делаю это:
Код: Выделить всё
CoroutineScope(Dispatchers.IO).launch {
val res = fetcherUseCase
.fetchData()
}
Код: Выделить всё
override suspend fun fetchData(): SomeResultObject {
val res = fetcher.fetchData()
return when (res) {
is Failure -> Result.Failure(res.error)
is Loading -> { Result.Loading }
is Success -> Result.Success(res.result)
}
}
Код: Выделить всё
suspend fun fetchData(): Result {
var url = ""
try {
.......
val call = NetworkProvider.okHttpClient.newCall(request)
url = call.request().toString()
val d = runBlocking { async { call.execute() } }
Log.d("---", "Here 1")
val response = withTimeout(1500L) {
d.await()
}
} catch (ex: TimeoutCancellationException) {
Log.d("---", "Here 2")
}
return Result.Loading
}
Что мне здесь не хватает?!
Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/784 ... und-thread