diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/BackgroundTaskUtil.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/BackgroundTaskUtil.java index 20899b5bf48683e14d18e1c46f4998d632429518..69e4ec6d07bba097b97aa2c06c773f9f1228c3fd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/BackgroundTaskUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/BackgroundTaskUtil.java @@ -205,67 +205,63 @@ public class BackgroundTaskUtil { @NotNull @CalledInAny public static ProgressIndicator executeOnPooledThread(@NotNull Disposable parent, @NotNull Runnable runnable) { - ModalityState modalityState = ModalityState.defaultModalityState(); - return runUnderDisposeAwareIndicator(runnable, parent, modalityState, true); - } - - @CalledInAny - private static ProgressIndicator runUnderDisposeAwareIndicator(@NotNull Runnable task, - @NotNull Disposable parent, - @NotNull ModalityState modalityState, - boolean onPooledThread) { - ProgressIndicator indicator = new EmptyProgressIndicator(modalityState); + ProgressIndicator indicator = new EmptyProgressIndicator(); indicator.start(); - if (onPooledThread) { - CompletableFuture<?> future = CompletableFuture.runAsync(() -> { - ProgressManager.getInstance().runProcess(task, indicator); - }, AppExecutorUtil.getAppExecutorService()); + CompletableFuture<?> future = CompletableFuture.runAsync(() -> { + ProgressManager.getInstance().runProcess(runnable, indicator); + }, AppExecutorUtil.getAppExecutorService()); - Disposable disposable = () -> { - if (indicator.isRunning()) indicator.cancel(); - try { - future.get(1, TimeUnit.SECONDS); - } - catch (ExecutionException e) { - if (e.getCause() instanceof ProcessCanceledException) { - // ignore: expected cancellation - } - else { - LOG.error(e); - } + Disposable disposable = () -> { + if (indicator.isRunning()) indicator.cancel(); + try { + future.get(1, TimeUnit.SECONDS); + } + catch (ExecutionException e) { + if (e.getCause() instanceof ProcessCanceledException) { + // ignore: expected cancellation } - catch (InterruptedException | TimeoutException e) { + else { LOG.error(e); } - }; - - if (!registerIfParentNotDisposed(parent, disposable)) { - indicator.cancel(); - return indicator; } - future.whenComplete((o, e) -> Disposer.dispose(disposable)); - } - else { - Disposable disposable = () -> { - if (indicator.isRunning()) indicator.cancel(); - }; - - if (!registerIfParentNotDisposed(parent, disposable)) { - indicator.cancel(); - return indicator; + catch (InterruptedException | TimeoutException e) { + LOG.error(e); } + }; - try { - ProgressManager.getInstance().runProcess(task, indicator); - } - finally { - Disposer.dispose(disposable); - } + if (!registerIfParentNotDisposed(parent, disposable)) { + indicator.cancel(); + return indicator; } + + future.whenComplete((o, e) -> Disposer.dispose(disposable)); + return indicator; } + @CalledInAny + public static void runUnderDisposeAwareIndicator(@NotNull Disposable parent, @NotNull Runnable task) { + ProgressIndicator indicator = new EmptyProgressIndicator(ModalityState.defaultModalityState()); + indicator.start(); + + Disposable disposable = () -> { + if (indicator.isRunning()) indicator.cancel(); + }; + + if (!registerIfParentNotDisposed(parent, disposable)) { + indicator.cancel(); + return; + } + + try { + ProgressManager.getInstance().runProcess(task, indicator); + } + finally { + Disposer.dispose(disposable); + } + } + private static boolean registerIfParentNotDisposed(@NotNull Disposable parent, @NotNull Disposable disposable) { return ReadAction.compute(() -> { if (Disposer.isDisposed(parent)) return false; @@ -280,11 +276,6 @@ public class BackgroundTaskUtil { }); } - @CalledInAny - public static void runUnderDisposeAwareIndicator(@NotNull Disposable parent, @NotNull Runnable task) { - runUnderDisposeAwareIndicator(task, parent, ModalityState.defaultModalityState(), false); - } - /** * Wraps {@link MessageBus#syncPublisher(Topic)} in a dispose check, * and throws a {@link ProcessCanceledException} if the project is disposed,