ProgressIndicatorUtils.kt for 191 is added
Relates to #KT-33939
This commit is contained in:
@@ -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 <T> awaitWithCheckCanceled(future: Future<T>) {
|
||||
while (true) {
|
||||
ProgressManager.checkCanceled()
|
||||
try {
|
||||
future.get(50, TimeUnit.MILLISECONDS)
|
||||
return
|
||||
} catch (e: TimeoutException) {
|
||||
// ignore
|
||||
} catch (e: Exception) {
|
||||
LOG.warn(e)
|
||||
throw ProcessCanceledException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user