Promise<TreePath> (Promise<? extends TreePath> promise) { if (promise == null && isValidThread()) { return rejectedPromise(); } AsyncPromise<TreePath> async = new AsyncPromise<>(); if (promise == null) { onValidThread(() -> async.setError("rejected")); } else { promise.onError(onValidThread(async::setError)); promise.onSuccess(onValidThread(path -> resolve(async, path))); } return async; }