تخطَّ إلى المحتوى

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.

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().