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.progress.util.ProgressIndicatorUtils
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
|
||||||
fun <T : Any> runInReadActionWithWriteActionPriorityWithPCE(f: () -> T): T {
|
fun <T : Any> runInReadActionWithWriteActionPriorityWithPCE(f: () -> T): T =
|
||||||
var r: T? = null
|
runInReadActionWithWriteActionPriority(f) ?: throw ProcessCanceledException()
|
||||||
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> runInReadActionWithWriteActionPriority(f: () -> T): T? {
|
fun <T : Any> runInReadActionWithWriteActionPriority(f: () -> T): T? {
|
||||||
var r: T? = null
|
if (with(ApplicationManager.getApplication()) { isDispatchThread && isUnitTestMode }) {
|
||||||
if (!with(ApplicationManager.getApplication()) { isDispatchThread && isUnitTestMode }) {
|
return f()
|
||||||
val complete = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority {
|
|
||||||
r = f()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!complete) return null
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
var r: T? = null
|
||||||
|
val complete = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority {
|
||||||
r = f()
|
r = f()
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
if (!complete) return null
|
||||||
|
return r!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Any> Project.runSynchronouslyWithProgress(progressTitle: String, canBeCanceled: Boolean, action: () -> T): T? {
|
fun <T : Any> Project.runSynchronouslyWithProgress(progressTitle: String, canBeCanceled: Boolean, action: () -> T): T? {
|
||||||
|
|||||||
Reference in New Issue
Block a user