Say I have two tasks that return the same result. ...
# coroutines
e
Say I have two tasks that return the same result. How can I wait for the first of the two tasks to complete?
e
Copy code
coroutineScope {
    val t1 = async { task1() }
    val t2 = async { task2() }
    select {
        t1.onAwait { /* t1 is first */ }
        t2.onAwait { /* t2 is first */ }
    }
    t1.cancel()
    t2.cancel() 
}
🙏 6
👍 1
e
Awesome, I was just looking at select