From 1d51e5b59b57d76811956a5cbab58b91d4f58c27 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 19 Sep 2017 11:43:23 +0300 Subject: [PATCH] Refactoring: reuse implementation --- .../org/jetbrains/kotlin/idea/ProgressUtil.kt | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) 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? {