Prevent multiple concurrent 'checkHideNonConfiguredNotifications' calls

This commit is contained in:
Pavel V. Talanov
2017-08-24 20:35:32 +03:00
parent 6953ae79e2
commit e3b7f6d698
@@ -23,6 +23,7 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KClass
object ConfigureKotlinNotificationManager: KotlinSingleNotificationManager<ConfigureKotlinNotification> {
@@ -66,16 +67,23 @@ interface KotlinSingleNotificationManager<in T: Notification> {
}
}
private val checkInProgress = AtomicBoolean(false)
fun checkHideNonConfiguredNotifications(project: Project) {
if (ConfigureKotlinNotificationManager.getVisibleNotifications(project).isNotEmpty()) {
ApplicationManager.getApplication().executeOnPooledThread {
DumbService.getInstance(project).waitForSmartMode()
if (getConfigurableModulesWithKotlinFiles(project).all(::isModuleConfigured)) {
ApplicationManager.getApplication().invokeLater {
ConfigureKotlinNotificationManager.expireOldNotifications(project)
}
if (checkInProgress.get() || ConfigureKotlinNotificationManager.getVisibleNotifications(project).isEmpty()) return
ApplicationManager.getApplication().executeOnPooledThread {
if (!checkInProgress.compareAndSet(false, true)) return@executeOnPooledThread
DumbService.getInstance(project).waitForSmartMode()
if (getConfigurableModulesWithKotlinFiles(project).all(::isModuleConfigured)) {
ApplicationManager.getApplication().invokeLater {
ConfigureKotlinNotificationManager.expireOldNotifications(project)
checkInProgress.set(false)
}
}
else {
checkInProgress.set(false)
}
}
}