void () { ReadTask.Continuation continuation; try { continuation = runUnderProgress(progressIndicator, readTask); } catch (Throwable e) { future.completeExceptionally(e); throw e; } if (continuation == null) { future.complete(null); } else if (!future.isCancelled()) { application.invokeLater(new Runnable() { @Override public void run() { if (future.isCancelled()) return; Disposer.dispose(listenerDisposable); // remove listener early to prevent firing it during continuation execution try { if (!progressIndicator.isCanceled()) { continuation.getAction().run(); } } finally { future.complete(null); } } @Override public String toString() { return "continuation of " + readTask; } }, continuation.getModalityState()); } }