我正在使用 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/