Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅返回Kotlin中两个并发异步挂起函数中的第一个函数的结果?_Kotlin - Fatal编程技术网

如何仅返回Kotlin中两个并发异步挂起函数中的第一个函数的结果?

如何仅返回Kotlin中两个并发异步挂起函数中的第一个函数的结果?,kotlin,Kotlin,下面是一个例子 如何更改上述内容,以便只返回第一个完成函数的值 suspend fun fasterUseful(): Int = coroutineScope { val one = async { doSomethingUsefulOne() } val two = async { doSomethingUsefulTwo() } // ????? one.await() || two.await() whichever faster

下面是一个例子

如何更改上述内容,以便只返回第一个完成函数的值

suspend fun fasterUseful(): Int = coroutineScope {
        val one = async { doSomethingUsefulOne() }
        val two = async { doSomethingUsefulTwo() }
        // ????? one.await() || two.await() whichever faster
    }
选择{
一.等等{it}
2.等等{it}
}
看<如果您不想赋予第一个子句优先权,请选择无偏见。

选择{
一.等等{it}
2.等等{it}
}
看<代码>如果不想赋予第一个子句优先级,请选择无偏见

suspend fun fasterUseful(): Int = coroutineScope {
        val one = async { doSomethingUsefulOne() }
        val two = async { doSomethingUsefulTwo() }
        // ????? one.await() || two.await() whichever faster
    }
select<Int> {
    one.onAwait { it }
    two.onAwait { it }
}