void (@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) { addValues(result, sortVariants(collectSync(result))); Future<List<? extends T>> future = ApplicationManager.getApplication().executeOnPooledThread(() -> sortVariants(collectAsync(result))); while (true) { try { ProgressManager.checkCanceled(); List<? extends T> moreValues = future.get(TIMEOUT, TimeUnit.MILLISECONDS); if (moreValues != null) { addValues(result, moreValues); break; } } catch (InterruptedException | CancellationException e) { break; } catch (TimeoutException ignored) { } catch (ExecutionException e) { LOG.error(e); break; } catch (ProcessCanceledException e) { future.cancel(true); throw e; } } result.stopHere(); }