/** * Determines if the promise is completed yet. * * @return <tt>true</tt> if the promise has either successfully completed or failed yet, <tt>false</tt> otherwise. */ public boolean isCompleted() { return isFailed() || isSuccessful(); }
/** * Adds a completion handler to this promise. * <p> * If the promise is already completed, the handler is immediately invoked. * * @param handler the handler to be notified once the promise is completed. A promise can notify more than one * handler. * @return <tt>this</tt> for fluent method chaining */ @Nonnull @SuppressWarnings("squid:S2589") @Explain("We really want to ensure that the given value is not null and not just rely on annotation.") public Promise<V> onComplete(@Nonnull CompletionHandler<V> handler) { if (handler != null) { if (isSuccessful()) { completeHandler(get(), handler); } else if (isFailed()) { failHandler(getFailure(), handler); } else { this.handlers.add(handler); logErrors = false; } } return this; }