Hey everyone, I need help with putting something together but I’m not too sure how to do so.
• I want to make 2 API calls in parallel (Call A and Call B)
• If Call A finishes first and is Successful, cancelCall Bthen return result of Call A
• If Call B finishes first and is Successful, cancelCall Athen return result of Call B
I currently have something like this:
Copy code
val callA = async { the call }
val callB = async { the call }
if (callA.await().isSuccess) {
callB.cancel()
return callA.await()
}else {
callA.cancel()
return callB.await()
}
However, it doesn’t quite get the behavior I want because I’m essentially only waiting for Call A to complete first before I even check on Call B. Can anyone offer some advice, please?