Anko协程kotlin中的Deferred是什么?
What is Deferred in Anko coroutines kotlin?
在 kotlin 的 Anko 协程库中,其中有一项功能 bg() 可以轻松地在后台线程上执行您的代码。 return 类型是 Deferred。那什么是Deferred?
引用Link
(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())
}
如果你打扰了,我首先要引用问题中第一个 link Deferred
class 文档中的第一句话:
Deferred value is a non-blocking cancellable future.
事实上,deferred 是future 或promise (see this wikipedia article) 的同义词。
Deferred
class 是 kotlinx-coroutines
project that provides library support for Kotlin coroutines. The recommended way to start learning more about it is by reading this guide 的一部分。
在 kotlin 的 Anko 协程库中,其中有一项功能 bg() 可以轻松地在后台线程上执行您的代码。 return 类型是 Deferred。那什么是Deferred?
引用Link
(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())
}
如果你打扰了,我首先要引用问题中第一个 link Deferred
class 文档中的第一句话:
Deferred value is a non-blocking cancellable future.
事实上,deferred 是future 或promise (see this wikipedia article) 的同义词。
Deferred
class 是 kotlinx-coroutines
project that provides library support for Kotlin coroutines. The recommended way to start learning more about it is by reading this guide 的一部分。