Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.socket.client.Socket
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import kotlinx.serialization.decodeFromByteArray
Expand Down Expand Up @@ -92,9 +93,9 @@ class ClusterService(

val sema = Semaphore(syncConfig.concurrency)

missingFiles.forEach { file ->
sema.withPermit {
async {
val jobs = missingFiles.map { file ->
async {
sema.withPermit {
try {
downloadFile(file)
logger.debug { "Downloaded: ${file.path}" }
Expand All @@ -106,6 +107,8 @@ class ClusterService(
}
}

jobs.awaitAll()

logger.info { "Sync completed: ${missingFiles.size} files" }
}

Expand Down
Loading