【发布时间】:2017-12-01 08:33:40
【问题描述】:
在 kotlin 的 Anko 协程库中,其中有一个功能 bg() 可以轻松地在后台线程上执行您的代码。在那个返回类型中是 Deferred。那么什么是延迟?
参考链接
(2) https://github.com/Kotlin/anko/wiki/Anko-Coroutines#bg
fun getData(): Data { ... }
fun showData(data: Data) { ... }
async(UI) {
val data: Deferred<Data> = bg {
// Runs in background
getData()
}
// This code is executed on the UI thread
showData(data.await())
}
【问题讨论】:
-
Deferred是 Kotlin 特定的未来/承诺。那有什么问题呢? -
我的问题是什么是延迟?
标签: android kotlin anko kotlin-coroutines