@CalledInAny
  private static @NotNull <T> Pair<T, ProgressIndicator> computeInBackgroundAndTryWait(@NotNull Function<? super ProgressIndicator, ? extends T> task,
                                                                                       @NotNull PairConsumer<? super T, ? super ProgressIndicator> asyncCallback,
                                                                                       @NotNull ModalityState modality,
                                                                                       long waitMillis) {
    ProgressIndicator indicator = new EmptyProgressIndicator(modality);
    indicator.start();

    Helper<T> helper = new Helper<>();

    ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
      T result = task.fun(indicator);
      if (!helper.setResult(result)) {
        asyncCallback.consume(result, indicator);
      }
    }, indicator));

    T result = null;
    if (helper.await(waitMillis)) {
      result = helper.getResult();
    }

    return Pair.create(result, indicator);
  }
@CalledInAny
  private static @NotNull <T> Pair<T, ProgressIndicator> computeInBackgroundAndTryWait(@NotNull Function<? super ProgressIndicator, ? extends T> task,
                                                                                       @NotNull PairConsumer<? super T, ? super ProgressIndicator> asyncCallback,
                                                                                       @NotNull ModalityState modality,
                                                                                       long waitMillis)