【发布时间】:2020-05-06 06:14:49
【问题描述】:
我正在尝试为我的协程创建惰性函数。我创建了这样的 util 函数。
fun <T> lazyCoroutine(scope: CoroutineScope, block: suspend CoroutineScope.() -> T): Lazy<T> {
val some = scope.async(start = CoroutineStart.LAZY) {
block.invoke(this)
}
return lazy {
some.await()
}
}
但是在终端显示
我也不想返回Deferred<T>,我只想从deferred返回。我看到大部分文章都返回Deferred<T>,这不适合我的场景。有没有相关的解决方案请指出。祝你有美好的一天!。
【问题讨论】:
标签: android android-architecture-components kotlin-coroutines