/** * Adds a completion handler to this promise which only handles the successful completion of the promise. * <p> * If the promise is already completed, the handler is immediately invoked. * * @param successHandler 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 */ public Future onSuccess(Runnable successHandler) { onSuccess(ignored -> successHandler.run()); return this; } }
/** * Determines if the framework is ready yet. * * @return <tt>true</tt> if the framework is ready, <tt>false</tt> otherwise. */ public boolean isReady() { if (ready == null) { if (schema == null) { return false; } ready = Boolean.FALSE; getReadyFuture().onSuccess(o -> ready = Boolean.TRUE); } return ready.booleanValue(); }
/** * Transforms a collection of items into a promise for a list of results while invoking an async function for * each item. * * @param input the items to iterate over * @param toPromiseHandler the async function which returns a promise to indicate completion * @param <I> the input type * @param <O> the output type generated by the async function * @return a promise containing the invocation results of the async function for each item in the input */ public static <I, O> Promise<List<O>> sequence(Iterable<I> input, Function<I, Promise<O>> toPromiseHandler) { Promise<List<O>> result = new Promise<>(); List<O> buffer = new ArrayList<>(); processChain(input, toPromiseHandler, (ignored, output) -> buffer.add(output)).onSuccess(() -> result.success( buffer)).onFailure(result::fail); return result; }