ProgressRunner: move modality semaphore and thread function closer to where they are actually used

GitOrigin-RevId: 2f4946597c9bcc125bebf763c6683c864f302b0d
This commit is contained in:
Daniil Ovchinnikov
2023-04-28 13:01:49 +00:00
committed by intellij-monorepo-bot
parent cf5427d3d7
commit 46f46a4c0a
@@ -223,27 +223,26 @@ public final class ProgressRunner<R> {
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<R> 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);
}