Await In Loop (ARCH8030)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
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().