anyOf equivalent of Kotlin Deffered

Coroutine async returns Deferred and there are example of lazy execution and usages of await.

However how can we wait for any of the Deffered instances to complete?

In a nutshell

  // whats the equivalent of CompletableFuture.anyOf(...)?
  // is this how we do it? if so how costly is this?
  select<Unit> {
     deffered1.onAwait {}
     deffered2.onAwait {}
  }

.merge(): Flow<T> is an alternative to select(). I’ve used it to address a similar problem (get the first in a collection of deferreds to complete with a non-null value). i.e.

deferreds.map { it::await.asFlow() }.merge().first()