From 46f46a4c0af4e72364c5b5bdfa58b6569f4439e2 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 26 Apr 2023 14:35:09 +0200 Subject: [PATCH] ProgressRunner: move modality semaphore and thread function closer to where they are actually used GitOrigin-RevId: 2f4946597c9bcc125bebf763c6683c864f302b0d --- .../openapi/progress/impl/ProgressRunner.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/progress/impl/ProgressRunner.java b/platform/core-impl/src/com/intellij/openapi/progress/impl/ProgressRunner.java index 4c50fb87fdeb..ce213ccb7887 100644 --- a/platform/core-impl/src/com/intellij/openapi/progress/impl/ProgressRunner.java +++ b/platform/core-impl/src/com/intellij/openapi/progress/impl/ProgressRunner.java @@ -223,27 +223,26 @@ public final class ProgressRunner { return progress; }); - Semaphore modalityEntered = new Semaphore(forceSyncExec ? 0 : 1); - Function<@NotNull ProgressIndicator, R> onThreadCallable = (progressIndicator) -> { - if (isModal) { - modalityEntered.waitFor(); - } - // runProcess handles starting/stopping progress and setting thread's current progress - return ProgressManager.getInstance().runProcess(() -> myComputation.apply(progressIndicator), progressIndicator); - }; - CompletableFuture resultFuture; if (forceSyncExec) { resultFuture = new CompletableFuture<>(); try { ProgressIndicator progressIndicator = progressFuture.join(); - resultFuture.complete(onThreadCallable.apply(progressIndicator)); + resultFuture.complete(ProgressManager.getInstance().runProcess(() -> myComputation.apply(progressIndicator), progressIndicator)); } catch (Throwable t) { resultFuture.completeExceptionally(t); } } else { + Semaphore modalityEntered = new Semaphore(1); + Function<@NotNull ProgressIndicator, R> onThreadCallable = (progressIndicator) -> { + if (isModal) { + modalityEntered.waitFor(); + } + // runProcess handles starting/stopping progress and setting thread's current progress + return ProgressManager.getInstance().runProcess(() -> myComputation.apply(progressIndicator), progressIndicator); + }; if (ApplicationManager.getApplication().isDispatchThread()) { resultFuture = execFromEDT(progressFuture, modalityEntered, onThreadCallable); }