mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
IJPL-210 remove default completeOnFinish parameter value in runAsCoroutine
This change also removes unneeded `runAsCoroutine` overload with `Runnable`. GitOrigin-RevId: aaa74f31eb7e92fee5eba9c4ed149f34fde1e025
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e3c5dd260a
commit
da14cea8cf
@@ -9,7 +9,7 @@ internal class CancellationBiConsumer<T, U>(
|
||||
private val runnable: BiConsumer<T, U>,
|
||||
) : BiConsumer<T, U> {
|
||||
override fun accept(t: T, u: U) {
|
||||
runAsCoroutine(job) {
|
||||
runAsCoroutine(job, completeOnFinish = true) {
|
||||
runnable.accept(t, u)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ internal class CancellationCallable<V>(
|
||||
) : Callable<V> {
|
||||
|
||||
override fun call(): V {
|
||||
return runAsCoroutine(job) {
|
||||
return runAsCoroutine(job, completeOnFinish = true) {
|
||||
callable.call()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class CancellationFunction<T, U> internal constructor(
|
||||
) : Function<T, U> {
|
||||
|
||||
override fun apply(t: T): U {
|
||||
return runAsCoroutine(job) {
|
||||
return runAsCoroutine(job, completeOnFinish = true) {
|
||||
function.apply(t)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ internal class CancellationRunnable(
|
||||
) : Runnable {
|
||||
|
||||
override fun run() {
|
||||
runAsCoroutine(job, runnable)
|
||||
runAsCoroutine(job, completeOnFinish = true, runnable::run)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
|
||||
@@ -12,7 +12,7 @@ internal class PeriodicCancellationRunnable(
|
||||
override fun run() {
|
||||
// don't complete the job, it can be either failed, or cancelled
|
||||
try {
|
||||
runAsCoroutine(job, false, runnable::run)
|
||||
runAsCoroutine(job, completeOnFinish = false, runnable::run)
|
||||
}
|
||||
catch (e: CancellationException) {
|
||||
// According to the specification of the FutureTask, the runnable should not throw in case of cancellation.
|
||||
|
||||
@@ -170,7 +170,7 @@ private fun isContextAwareComputation(runnable: Any): Boolean {
|
||||
*/
|
||||
@Internal
|
||||
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
|
||||
fun <T> runAsCoroutine(job: CompletableJob, completeOnFinish: Boolean = true, action: () -> T): T {
|
||||
fun <T> runAsCoroutine(job: CompletableJob, completeOnFinish: Boolean, action: () -> T): T {
|
||||
val originalPCE: Ref<ProcessCanceledException> = Ref(null)
|
||||
val deferred = GlobalScope.async(
|
||||
// we need to have a job in CoroutineContext so that `Deferred` becomes its child and properly delays cancellation
|
||||
@@ -200,12 +200,6 @@ fun <T> runAsCoroutine(job: CompletableJob, completeOnFinish: Boolean = true, ac
|
||||
return deferred.getCompleted()
|
||||
}
|
||||
|
||||
/**
|
||||
* A runnable-friendly overload for usage in Java
|
||||
* @see runAsCoroutine
|
||||
*/
|
||||
fun runAsCoroutine(job: CompletableJob, r: Runnable): Unit = runAsCoroutine(job, action = r::run)
|
||||
|
||||
internal fun capturePropagationAndCancellationContext(command: Runnable): Runnable {
|
||||
if (isContextAwareComputation(command)) {
|
||||
return command
|
||||
|
||||
Reference in New Issue
Block a user