IJPL-149042 wrap work with channels into try-finally

GitOrigin-RevId: 6854c66fa9ca496ab6c9b24d9c8e1c62db2fc6ed
This commit is contained in:
Max Medvedev
2024-09-27 16:57:46 +02:00
committed by intellij-monorepo-bot
parent 4d6044e054
commit 597b3204f9

View File

@@ -157,16 +157,20 @@ internal suspend fun searchAndSendEntities(
val classesChannel = if (settings.shouldIndexClasses) Channel<IndexableEntity>(capacity = BUFFER_SIZE) else null
val symbolsChannel = if (settings.shouldIndexSymbols) Channel<IndexableEntity>(capacity = BUFFER_SIZE) else null
if (filesChannel != null) launch { sendEntities(project, IndexId.FILES, filesChannel) }
if (classesChannel != null) launch { sendEntities(project, IndexId.CLASSES, classesChannel) }
if (symbolsChannel != null) launch { sendEntities(project, IndexId.SYMBOLS, symbolsChannel) }
try {
if (filesChannel != null) launch { sendEntities(project, IndexId.FILES, filesChannel) }
if (classesChannel != null) launch { sendEntities(project, IndexId.CLASSES, classesChannel) }
if (symbolsChannel != null) launch { sendEntities(project, IndexId.SYMBOLS, symbolsChannel) }
coroutineScope {
launchSearching(this, filesChannel, classesChannel, symbolsChannel)
coroutineScope {
launchSearching(this, filesChannel, classesChannel, symbolsChannel)
}
}
finally {
// Here all producer coroutines launch from launchSearching finished,
// so we can close channels to make consumer coroutines finish
filesChannel?.close()
classesChannel?.close()
symbolsChannel?.close()
}
// Here all producer coroutines launch from launchSearching finished,
// so we can close channels to make consumer coroutines finish
filesChannel?.close()
classesChannel?.close()
symbolsChannel?.close()
}