Await In Loop (ARCH8030)
Key kotlin.async.await-in-loop · Severity info · Category async
Flags .await() inside a loop body - each iteration waits for the previous one, serialising work that could run concurrently.
Incorrect
Section titled “Incorrect”for (id in ids) { results += async { fetch(id) }.await()}Correct
Section titled “Correct”val results = ids.map { id -> async { fetch(id) } }.awaitAll()Start all the deferreds first, then awaitAll().