我想创建一个具有返回值的协程方法.
例如)
fun funA() = async(CommonPool) {
return 1
}
fun funB() = async(CommonPool) {
return 2
}
fun sum() {
launch {
val total = funA().await() + funB().await()
}
}
Run Code Online (Sandbox Code Playgroud)
如果我想要求总和方法,我该怎么办?
喜欢,
fun sum(): Int {
launch {
val total = funA().await() + funB().await()
}
return total
}
Run Code Online (Sandbox Code Playgroud)