Aller au contenu

Await In Loop (ARCH8030)

Ce contenu n’est pas encore disponible dans votre langue.

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.

for (id in ids) {
results += async { fetch(id) }.await()
}
val results = ids.map { id -> async { fetch(id) } }.awaitAll()

Start all the deferreds first, then awaitAll().