awaitAll implementation

Hello,
Is there any difference between:

list.awaitAll()		       // A

list.map { it.await() }    // B

I checked awaitAll implementation and it seems fairly complicated. Further, it will convert the list to an array, and then create another array of size n, which seems inefficient.

Can anyone shed some light on why awaitAll has such a complex implementation (at first glance)?

Thanks!

As the documentation of awaitAll() states:

This function is not equivalent to deferreds.map { it.await() } which fails only when it sequentially gets to wait for the failing deferred, while this awaitAll fails immediately as soon as any of the deferreds fail.

But I don’t know if there are other differences.

1 Like

@broot Fascinating, thanks for pointing that out!

But if these are in a coroutineScope should it matter?

    coroutineScope {
        // ...
        list.map { it.await() }
    }

This would still fail as soon as the first one fails. Maybe it’s only different in supervisorScope?