I have two suspend functions:
suspend fun sendData() : Boolean
suspend fun awaitAcknowledge() : Boolean
and I want to wrap them in a third suspend function in which they should be executed in parallel and I want to calculate the final result by having both return values:
suspend fun sendDataAndAwaitAcknowledge() : Boolean {
// TODO execute both in parallel and compare both results
}
However, if I write it like that,
suspend fun sendDataAndAwaitAcknowledge() : Boolean {
val sendResult = sendData()
val receiveAck = awaitAcknowledge()
}
the functions will be executed in a serial order, which will not work in my case.
Coming from RxJava, I would like to achieve something like the zip
operator:
Single.zip(awaitAcknowledge(), sendData(), {receiveAck, sendResult -> ...})
How can I do this with Coroutines
?