Promise<T> (@NotNull AsyncPromise<T> promise) { final Promise<T> effectivePromise; try { effectivePromise = load(promise); if (effectivePromise != promise) { ref.compareAndSet(promise, effectivePromise); } } catch (Throwable e) { ref.compareAndSet(promise, null); rejectAndDispose(promise); //noinspection InstanceofCatchParameter throw e instanceof RuntimeException ? ((RuntimeException)e) : new RuntimeException(e); } effectivePromise.onSuccess(doneHandler); if (isCancelOnReject()) { effectivePromise.onError(throwable -> ref.compareAndSet(effectivePromise, null)); } if (effectivePromise != promise) { effectivePromise.processed(promise); } return effectivePromise; }