void (@NotNull ProgressIndicator indicator) { CountDownLatch countDownLatch = new CountDownLatch(1); runner.run().whenComplete((o, throwable) -> { countDownLatch.countDown(); }); final ScheduledExecutorService myExecutor = ConcurrencyUtil.newSingleScheduledThreadExecutor("Performance plugin script runner"); myExecutor.scheduleWithFixedDelay(() -> { if (indicator.isCanceled()) { runner.stop(); } }, 0, 100, TimeUnit.MILLISECONDS); try { countDownLatch.await(); } catch (InterruptedException ignored) { } myExecutor.shutdownNow(); }