From c0c929c449211e45cf032e0a6f138099ccb6ce1a Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Fri, 17 Jan 2020 11:39:44 +0100 Subject: [PATCH] ProgressIndicatorUtils.kt for 191 is added Relates to #KT-33939 --- .../idea/util/ProgressIndicatorUtils.kt.191 | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt.191 diff --git a/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt.191 b/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt.191 new file mode 100644 index 00000000000..19f12247ab0 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/util/ProgressIndicatorUtils.kt.191 @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.util + +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.progress.ProcessCanceledException +import com.intellij.openapi.progress.ProgressManager +import java.util.concurrent.Future +import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeoutException + +object ProgressIndicatorUtils { + private val LOG = Logger.getInstance(ProgressIndicatorUtils::class.java) + + @JvmStatic + fun awaitWithCheckCanceled(future: Future) { + while (true) { + ProgressManager.checkCanceled() + try { + future.get(50, TimeUnit.MILLISECONDS) + return + } catch (e: TimeoutException) { + // ignore + } catch (e: Exception) { + LOG.warn(e) + throw ProcessCanceledException(e) + } + } + } + +} \ No newline at end of file