mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
IJPL-210 add ChildContext.runAsCoroutine
GitOrigin-RevId: d22b6ac9b97c4ea2cc4965b195c748aee0acb0b5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
caa4ad0a0c
commit
e3c5dd260a
@@ -461,12 +461,7 @@ public final class ProgressRunner<R> {
|
||||
Runnable contextRunnable = context.equals(EmptyCoroutineContext.INSTANCE) ? runnable : (ContextAwareRunnable)() -> {
|
||||
CoroutineContext effectiveContext = context.plus(asContextElement(progressIndicator.getModalityState()));
|
||||
try (AccessToken ignored = ThreadContext.installThreadContext(effectiveContext, false)) {
|
||||
if (job != null) {
|
||||
Propagation.runAsCoroutine(job, runnable);
|
||||
}
|
||||
else {
|
||||
runnable.run();
|
||||
}
|
||||
childContext.runAsCoroutine(runnable);
|
||||
}
|
||||
};
|
||||
switch (myThreadToUse) {
|
||||
|
||||
@@ -366,8 +366,7 @@ public class Alarm implements Disposable {
|
||||
try (AccessToken ignored = ClientId.withClientId(myClientId)) {
|
||||
if (myChildContext != null) {
|
||||
try (AccessToken ignored2 = ThreadContext.installThreadContext(myChildContext.getContext(), true)) {
|
||||
CompletableJob job = myChildContext.getJob();
|
||||
QueueProcessor.runSafely(job == null ? task : () -> Propagation.runAsCoroutine(job, task));
|
||||
QueueProcessor.runSafely(() -> myChildContext.runAsCoroutine(task));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -110,13 +110,7 @@ public abstract class Update extends ComparableObject.Impl implements Runnable {
|
||||
}
|
||||
else {
|
||||
try (AccessToken ignored = ThreadContext.installThreadContext(myChildContext.getContext(), true)) {
|
||||
CompletableJob job = myChildContext.getJob();
|
||||
if (job != null) {
|
||||
Propagation.runAsCoroutine(job, this);
|
||||
}
|
||||
else {
|
||||
run();
|
||||
}
|
||||
myChildContext.runAsCoroutine(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ import com.intellij.util.childScope
|
||||
import com.intellij.util.concurrency.AppExecutorUtil
|
||||
import com.intellij.util.concurrency.ChildContext
|
||||
import com.intellij.util.concurrency.createChildContext
|
||||
import com.intellij.util.concurrency.runAsCoroutine
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.ui.StartupUiUtil.addAwtListener
|
||||
import com.intellij.util.xml.dom.XmlElement
|
||||
@@ -1311,14 +1310,8 @@ open class ActionManagerImpl protected constructor(private val coroutineScope: C
|
||||
|
||||
override fun run() {
|
||||
installThreadContext(childContext.context).use {
|
||||
val job = childContext.job
|
||||
if (job == null) {
|
||||
timerListener.run()
|
||||
}
|
||||
else {
|
||||
// this is periodic runnable that is invoked on timer; it should not complete a parent job
|
||||
runAsCoroutine(job = job, completeOnFinish = false, action = timerListener::run)
|
||||
}
|
||||
// this is periodic runnable that is invoked on timer; it should not complete a parent job
|
||||
childContext.runAsCoroutine(completeOnFinish = false, timerListener::run)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,13 +326,7 @@ public class MergingTaskQueue<T extends MergeableQueueTask<T>> {
|
||||
beforeTask();
|
||||
if (AppExecutorUtil.propagateContextOrCancellation() && myChildContext != null) {
|
||||
try (AccessToken ignored = ThreadContext.installThreadContext(myChildContext.getContext(), true)) {
|
||||
CompletableJob job = myChildContext.getJob();
|
||||
if (job != null) {
|
||||
Propagation.runAsCoroutine(job, () -> myTask.perform(indicator));
|
||||
}
|
||||
else {
|
||||
myTask.perform(indicator);
|
||||
}
|
||||
myChildContext.runAsCoroutine(() -> myTask.perform(indicator));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -75,7 +75,21 @@ class BlockingJob(val blockingJob: Job) : AbstractCoroutineContextElement(Blocki
|
||||
data class ChildContext internal constructor(
|
||||
val context: CoroutineContext,
|
||||
val job: CompletableJob?,
|
||||
)
|
||||
) {
|
||||
|
||||
fun runAsCoroutine(action: Runnable) {
|
||||
runAsCoroutine(completeOnFinish = true, action::run)
|
||||
}
|
||||
|
||||
fun <T> runAsCoroutine(completeOnFinish: Boolean, action: () -> T): T {
|
||||
return if (job == null) {
|
||||
action()
|
||||
}
|
||||
else {
|
||||
runAsCoroutine(job, completeOnFinish, action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Internal
|
||||
fun createChildContext(): ChildContext {
|
||||
|
||||
Reference in New Issue
Block a user