mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ProgressRunner: move modality semaphore and thread function closer to where they are actually used
GitOrigin-RevId: 2f4946597c9bcc125bebf763c6683c864f302b0d
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user