Refactoring: reuse implementation
This commit is contained in:
@@ -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? {
|
||||
|
||||
Reference in New Issue
Block a user