diff --git a/idea/src/org/jetbrains/kotlin/idea/ProgressUtil.kt b/idea/src/org/jetbrains/kotlin/idea/ProgressUtil.kt index e3d51869b52..4450c3ea973 100644 --- a/idea/src/org/jetbrains/kotlin/idea/ProgressUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/ProgressUtil.kt @@ -22,37 +22,21 @@ import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.util.ProgressIndicatorUtils import com.intellij.openapi.project.Project -fun runInReadActionWithWriteActionPriorityWithPCE(f: () -> T): T { - var r: T? = null - if (!with(ApplicationManager.getApplication()) { isDispatchThread && isUnitTestMode }) { - val complete = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority { - r = f() - } - - // There is a write action in progress or pending, so no point in counting the result - if (!complete) throw ProcessCanceledException() - } - else { - r = f() - } - - return r!! -} +fun runInReadActionWithWriteActionPriorityWithPCE(f: () -> T): T = + runInReadActionWithWriteActionPriority(f) ?: throw ProcessCanceledException() fun runInReadActionWithWriteActionPriority(f: () -> T): T? { - var r: T? = null - if (!with(ApplicationManager.getApplication()) { isDispatchThread && isUnitTestMode }) { - val complete = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority { - r = f() - } - - if (!complete) return null + if (with(ApplicationManager.getApplication()) { isDispatchThread && isUnitTestMode }) { + return f() } - else { + + var r: T? = null + val complete = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority { r = f() } - return r + if (!complete) return null + return r!! } fun Project.runSynchronouslyWithProgress(progressTitle: String, canBeCanceled: Boolean, action: () -> T): T? {