【发布时间】:2019-06-20 21:16:30
【问题描述】:
一般来说,suspend funs 不能用来代替普通的funs。如果你尝试直接从普通的fun 调用suspend fun,你会得到一个编译时错误。
This blog post 提到你可以通过编写在 Kotlin 中做一个并发映射
list.map { async { f(it) } }.map { it.await() }
为什么第二个map 编译?您通常不能通过suspend fun 代替fun。是吗
-
map是inline fun,并且自动推断为“上游”暂停 -
map是 Kotlin 以某种方式特殊处理的 - 还有别的吗?
【问题讨论】: