Skip to content

fix: 修正 syncFiles 并发限制与等待,确保全部下载完成#4

Open
sdjnmxd wants to merge 2 commits intobangbang93:masterfrom
sdjnmxd:master
Open

fix: 修正 syncFiles 并发限制与等待,确保全部下载完成#4
sdjnmxd wants to merge 2 commits intobangbang93:masterfrom
sdjnmxd:master

Conversation

@sdjnmxd
Copy link
Copy Markdown
Contributor

@sdjnmxd sdjnmxd commented Oct 28, 2025

No description provided.

@bangbang93 bangbang93 requested a review from Copilot October 29, 2025 03:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug in the file synchronization logic where async download jobs were created but never awaited, causing the function to return prematurely before downloads completed.

  • Refactored the file download loop to properly collect async jobs and await their completion
  • Added awaitAll() import to support waiting for all concurrent downloads
  • Changed from forEach pattern to map + awaitAll() pattern for proper async handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +96 to +110
val jobs = missingFiles.map { file ->
async {
sema.withPermit {
try {
downloadFile(file)
logger.debug { "Downloaded: ${file.path}" }
} catch (e: Exception) {
logger.error(e) { "Failed to download ${file.path}" }
throw e
}
}
}
}

jobs.awaitAll()
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: the new code uses tabs while the rest of the file uses spaces (4 spaces per indentation level). Please convert the tabs to spaces to match the existing code style.

Suggested change
val jobs = missingFiles.map { file ->
async {
sema.withPermit {
try {
downloadFile(file)
logger.debug { "Downloaded: ${file.path}" }
} catch (e: Exception) {
logger.error(e) { "Failed to download ${file.path}" }
throw e
}
}
}
}
jobs.awaitAll()
val jobs = missingFiles.map { file ->
async {
sema.withPermit {
try {
downloadFile(file)
logger.debug { "Downloaded: ${file.path}" }
} catch (e: Exception) {
logger.error(e) { "Failed to download ${file.path}" }
throw e
}
}
}
}
jobs.awaitAll()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants