Return value only of the faster coroutine
问题 How can I run multiple coroutines in parallel and return only the value of the one that finishes first? Real-life scenario, I have two data sources - Database and API service . I don't care where does the data originate from, I just need it fast. How can I query both Database and API service and cancel the other request when the one finishes? In RxJava world this would be equal to Amb operator. How can I achieve similar behaviour using coroutines? 回答1: I came up with following implementation: