Why not just cancel the scope when a child wins? A basic approach:
suspend fun awaitTrigger() { coroutineScope {
val scope = this
launch { awaitAutomaticTrigger(); scope.cancel() }
launch { awaitManualTrigger(); scope.cancel() }
} }
It should gracefully cancel all losers. Also more flexible: we can for example always wait for some specific slow child by skipping cancel invocation.
Marek Langiewicz Nope, the winner's job is not finished until after the launch block is complete, so cancellation happens before, so it cannot work.
Here's a playground that proves it: pl.kotl.in/MArMNltGT