android - anko bg 的替代品是什么?

标签 android kotlin anko kotlin-coroutines

我正在使用 anko bg 功能来管理后台任务。

代码如下

import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.Request
import com.github.kittinunf.fuel.core.Response
import com.github.kittinunf.result.Result
import org.jetbrains.anko.coroutines.experimental.bg

object AuthenticationService {
    suspend fun login(login: Login): Triple<Request, Response, Result<GenResponse, FuelError>> {
        return bg {
            HttpService.post<GenResponse>("/auth/login",login.toJsonString())
        }.await()
    }
}

它显示 bg 已被弃用并要求我使用 async(block)

如何用异步替换这个后台任务?

最佳答案

考虑为不同类型的后台任务创建您自己的 ThreadPoolExecutor,并将它们用作协程调度程序。

而且你总是可以看看Anko bg source code供引用。

关于android - anko bg 的替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56142234/

相关文章:

java - 是否可以使用 Java ImageIO 从 InputStream 读取多个图像?

kotlin Junit 测试函数语法

android - 如何在 anko 中为按钮设置图标(可绘制)?

Android Mediaplayer 音量波动

android - Google 移动广告 SDK v17.0.0 中无法获取提供商 com.google.android.gms.ads.MobileAdsInitProvider 错误

android - 为什么生成的 ViewDataBinding 类将 "include"标记的属性注释为 Nullable

android - 无法获取类型对象的未知属性 'anko_version'...?

android - Anko - 为 gridLayout 中的元素设置行和列值

android - 访问 Androids 流量统计

android - java.lang.IllegalArgumentException : Can only use lower 16 bits for requestCode