/** * Determines if the promise was successfully completed yet. * * @return <tt>true</tt> if the promise was successfully completed, <tt>false</tt> otherwise. */ public boolean isSuccessful() { return value != null && !isFailed(); }
/** * 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(); }
@Override public void onSuccess(@Nullable V value) throws Exception { if (!result.isFailed()) { // onSuccess can be called from any thread -> sync on resultList... synchronized (resultList) { resultList.set(currentIndex, value); } // Keep track how many results we're waiting for and forward the result when we're finished. latch.countDown(); if (latch.getCount() <= 0) { result.success(resultList); } } }
/** * 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; }