ProgressIndicator (@NotNull Function<? super ProgressIndicator, /*@NotNull*/ ? extends Runnable> backgroundTask, @Nullable Runnable onSlowAction, long waitMillis, boolean forceEDT) { ModalityState modality = ModalityState.current(); if (forceEDT) { ProgressIndicator indicator = new EmptyProgressIndicator(modality); try { Runnable callback = ProgressManager.getInstance().runProcess(() -> backgroundTask.fun(indicator), indicator); finish(callback, indicator); } catch (ProcessCanceledException ignore) { } catch (Throwable t) { LOG.error(t); } return indicator; } else { Pair<Runnable, ProgressIndicator> pair = computeInBackgroundAndTryWait( backgroundTask, (callback, indicator) -> ApplicationManager.getApplication().invokeLater(() -> finish(callback, indicator), modality), modality, waitMillis); Runnable callback = pair.first; ProgressIndicator indicator = pair.second; if (callback != null) { finish(callback, indicator); } else { if (onSlowAction != null) onSlowAction.run(); } return indicator; } }