Android75
03/21/2022, 7:02 AMcustomScope.launch{
action1()
action2()
i’d like launch in parallel and when 2 methods end your action i have to invoke a methodRonald Wolvers
03/21/2022, 7:25 AMasync() instead of launch() in this case, so that can you can call await() and wait for the result(s). Check out: https://kotlinlang.org/docs/composing-suspending-functions.html#concurrent-using-asyncAndroid75
03/21/2022, 7:28 AM*val* one = async { doSomethingUsefulOne() }
*val* two = async { doSomethingUsefulTwo() }
i don’t understand how invoke a method when both async has finished your actionsRonald Wolvers
03/21/2022, 7:35 AMawait() on both of them, whichever finished first will return immediately, whereas the one that is taking longer will block until it's done.Ronald Wolvers
03/21/2022, 7:36 AMawait() on both then it will block for 10 seconds, but as two already finished in the meantime, your execution time will be 10 seconds in total (roughly of course)Paul Woitaschek
03/21/2022, 7:45 AMcustomScope.launch {
coroutineScope {
launch { action1() }
launch { action2() }
}
println("action1 and action2 finished")
doSthNow()
}Paul Woitaschek
03/21/2022, 7:46 AMAndroid75
03/21/2022, 8:08 AMPaul Woitaschek
03/21/2022, 8:10 AM