Promise<TreePath> (@NotNull JTree tree) { AtomicReference<TreePath> reference = new AtomicReference<>(); AsyncPromise<TreePath> promise = new AsyncPromise<>(); promiseMakeVisible(tree, path -> { TreePath parent = reference.getAndSet(path); if (getPathCount(parent) == getPathCount(path.getParentPath())) return TreeVisitor.Action.CONTINUE; internalSelect(tree, parent); promise.setResult(parent); return TreeVisitor.Action.INTERRUPT; }, promise) .onError(promise::setError) .onSuccess(path -> { if (!promise.isDone()) { TreePath tail = reference.get(); if (tail == null || isHiddenRoot(tree, tail)) { promise.cancel(); } else { internalSelect(tree, tail); promise.setResult(tail); } } }); return promise; }