Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor, @Nullable Consumer<? super TreePath> consumer) { AsyncPromise<TreePath> promise = new AsyncPromise<>(); promiseMakeVisible(tree, visitor, promise) .onError(promise::setError) .onSuccess(path -> { if (promise.isCancelled()) { return; } EdtInvocationManager.invokeLaterIfNeeded(() -> { if (promise.isCancelled()) return; if (tree.isVisible(path)) { if (consumer != null) consumer.accept(path); promise.setResult(path); } else { promise.cancel(); } }); }); return promise; }