什么是在Anko协程kotlin推迟?

在kotlin的Anko coroutines库中,有一个特性bg()用于在后台线程上轻松地执行你的代码。 在那个返回类型是Deferred 。 那么什么是延期

Refrence链接

(1) https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Deferred.kt

(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课程的文档中引用第一句话开始:

延期价值是一个不可阻挡的可取消未来。

事实上,延期是未来承诺的代名词( 参见本维基百科文章 )。

Deferred类是kotlinx-coroutines项目的一部分,为Kotlin协同程序提供了库支持。 开始学习更多关于它的推荐方法是阅读本指南 。