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:
Daniil Ovchinnikov
2023-08-18 17:26:27 +02:00
committed by intellij-monorepo-bot
parent e3c5dd260a
commit da14cea8cf
6 changed files with 6 additions and 12 deletions

View File

@@ -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)
}
}

View File

@@ -18,7 +18,7 @@ internal class CancellationCallable<V>(
) : Callable<V> {
override fun call(): V {
return runAsCoroutine(job) {
return runAsCoroutine(job, completeOnFinish = true) {
callable.call()
}
}

View File

@@ -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)
}
}

View File

@@ -15,7 +15,7 @@ internal class CancellationRunnable(
) : Runnable {
override fun run() {
runAsCoroutine(job, runnable)
runAsCoroutine(job, completeOnFinish = true, runnable::run)
}
override fun toString(): String {

View File

@@ -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.

View File

@@ -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