Refactoring: reuse implementation

This commit is contained in:
Nikolay Krasko
2017-09-19 11:43:23 +03:00
parent 5a8c957edc
commit 1d51e5b59b
@@ -22,37 +22,21 @@ import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.util.ProgressIndicatorUtils
import com.intellij.openapi.project.Project
fun <T : Any> 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 <T : Any> runInReadActionWithWriteActionPriorityWithPCE(f: () -> T): T =
runInReadActionWithWriteActionPriority(f) ?: throw ProcessCanceledException()
fun <T : Any> 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 <T : Any> Project.runSynchronouslyWithProgress(progressTitle: String, canBeCanceled: Boolean, action: () -> T): T? {