From a121d9b56d10aaf590d874174be109ec05e4897e Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Fri, 28 Oct 2016 15:23:46 +0200 Subject: [PATCH] wait for pending filters in cmake console --- .../execution/impl/AsyncFilterRunner.java | 16 +++++++++++++--- .../execution/impl/EditorHyperlinkSupport.java | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java b/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java index 760b1f87d898..14af50403a23 100644 --- a/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java +++ b/platform/platform-impl/src/com/intellij/execution/impl/AsyncFilterRunner.java @@ -94,25 +94,35 @@ class AsyncFilterRunner { return applyResults.get(); } - private void handleSynchronouslyIfQuick(AtomicBoolean handled, Future future, int timeout) { + private boolean handleSynchronouslyIfQuick(AtomicBoolean handled, Future future, long timeout) { try { future.get(timeout, TimeUnit.MILLISECONDS).applyHighlights(myHyperlinks); handled.set(true); myPendingFilterResults.remove(handled); + return true; } catch (TimeoutException ignored) { + return false; } catch (Exception e) { throw new RuntimeException(e); } } - public void waitForPendingFilters() { + public boolean waitForPendingFilters(long timeoutMs) { ApplicationManager.getApplication().assertIsDispatchThread(); + + long started = System.currentTimeMillis(); while(!myPendingFilterResults.isEmpty()) { Map.Entry> next = myPendingFilterResults.entrySet().iterator().next(); - handleSynchronouslyIfQuick(next.getKey(), next.getValue(), 1000); + + timeoutMs -= System.currentTimeMillis() - started; + if (timeoutMs < 1) return false; + + if (!handleSynchronouslyIfQuick(next.getKey(), next.getValue(), timeoutMs)) return false; } + + return true; } @NotNull diff --git a/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java b/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java index 87c56122c612..2af4e82824e1 100644 --- a/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java +++ b/platform/platform-impl/src/com/intellij/execution/impl/EditorHyperlinkSupport.java @@ -110,8 +110,9 @@ public class EditorHyperlinkSupport { } } - public void waitForPendingFilters() { - myFilterRunner.waitForPendingFilters(); + @SuppressWarnings("SameParameterValue") + public void waitForPendingFilters(long timeoutMs) { + myFilterRunner.waitForPendingFilters(timeoutMs); } @Deprecated