From 597b3204f9fd96bee4f1cb6b054e1cde98ef44a0 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Fri, 27 Sep 2024 16:57:46 +0200 Subject: [PATCH] IJPL-149042 wrap work with channels into try-finally GitOrigin-RevId: 6854c66fa9ca496ab6c9b24d9c8e1c62db2fc6ed --- .../indexer/FileBasedEmbeddingIndexer.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/platform/ml-embeddings/src/com/intellij/platform/ml/embeddings/indexer/FileBasedEmbeddingIndexer.kt b/platform/ml-embeddings/src/com/intellij/platform/ml/embeddings/indexer/FileBasedEmbeddingIndexer.kt index d44b8344e16f..cad1fd1f8585 100644 --- a/platform/ml-embeddings/src/com/intellij/platform/ml/embeddings/indexer/FileBasedEmbeddingIndexer.kt +++ b/platform/ml-embeddings/src/com/intellij/platform/ml/embeddings/indexer/FileBasedEmbeddingIndexer.kt @@ -157,16 +157,20 @@ internal suspend fun searchAndSendEntities( val classesChannel = if (settings.shouldIndexClasses) Channel(capacity = BUFFER_SIZE) else null val symbolsChannel = if (settings.shouldIndexSymbols) Channel(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() }