Package org.forgerock.util.promise
Class Promises
- java.lang.Object
- 
- org.forgerock.util.promise.Promises
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classPromises.ResultsOrdered list of joined asynchronous results.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static Promise<Void,NeverThrowsException>allDone(Collection<Promise<?,?>> promises)Returns aPromisewhich will be completed successfully once all of the provided promises have completed (successfully or not, including runtime exceptions).static <V> Promise<V,NeverThrowsException>allDone(Collection<Promise<?,?>> promises, V context)Returns aPromisewhich will be completed successfully once all of the provided promises have completed (successfully or not, including runtime exceptions), returning back thecontextparameter.static <V,E extends Exception>
 Optional<Promise<V,E>>anyResultFrom(Stream<Promise<V,E>> promises)Takes a stream of promises that may not yet be resolved and returns a resolved value from them, or if none resolve to a result, the failure from the last.static Promise<Promises.Results,Exception>join(List<Promise<?,? extends Exception>> promises)Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.static Promise<Promises.Results,Exception>join(Promise<?,? extends Exception>... promises)Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.static <V,E extends Exception>
 Promise<V,E>newExceptionPromise(E exception)Returns aPromiserepresenting an asynchronous task which has already failed with the provided exception.static <V,E extends Exception>
 Promise<V,E>newPromise(Supplier<V,E> supplier)Execute a task and return the result as aPromise.static <V,E extends Exception>
 Promise<V,E>newResultPromise(V result)Returns aPromiserepresenting an asynchronous task which has already succeeded with the provided result.static <V,E extends Exception>
 Promise<V,E>newRuntimeExceptionPromise(RuntimeException exception)Returns aPromiserepresenting an asynchronous task which has already failed with the provided runtime exception.static <E extends Exception>
 Promise<Void,E>newVoidResultPromise()Returns aPromiserepresenting an asynchronous task which has already succeeded without result.static <V,E extends Exception>
 Promise<List<V>,E>when(List<Promise<V,E>> promises)Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.static <V,E extends Exception>
 Promise<List<V>,E>when(Promise<V,E>... promises)Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.
 
- 
- 
- 
Method Detail- 
newPromisepublic static <V,E extends Exception> Promise<V,E> newPromise(Supplier<V,E> supplier) Execute a task and return the result as aPromise.If the task executed successfully, then the Promiseis completed with the returned result of the task's execution.If the task failed during its execution then the Promiseis completed with the caughtException(orRuntimeException).- Type Parameters:
- V- The type of the task's result, or- Voidif the task does not return anything (i.e. it only has side-effects).
- E- The type of the exception thrown by the task if it fails, or- NeverThrowsExceptionif the task cannot fail.
- Parameters:
- supplier- The supplier that computes the result or throw an exception in case of failure.
- Returns:
- A Promiserepresenting a completed asynchronous task.
 
 - 
newRuntimeExceptionPromisepublic static <V,E extends Exception> Promise<V,E> newRuntimeExceptionPromise(RuntimeException exception) Returns aPromiserepresenting an asynchronous task which has already failed with the provided runtime exception. Attempts to get the result will immediately fail, and any listeners registered against the returned promise will be immediately invoked in the same thread as the caller.- Type Parameters:
- V- The type of the task's result, or- Voidif the task does not return anything (i.e. it only has side-effects).
- E- The type of the exception thrown by the task if it fails, or- NeverThrowsExceptionif the task cannot fail.
- Parameters:
- exception- The exception indicating why the asynchronous task has failed.
- Returns:
- A Promiserepresenting an asynchronous task which has already failed with the provided exception.
 
 - 
newExceptionPromisepublic static <V,E extends Exception> Promise<V,E> newExceptionPromise(E exception) Returns aPromiserepresenting an asynchronous task which has already failed with the provided exception. Attempts to get the result will immediately fail, and any listeners registered against the returned promise will be immediately invoked in the same thread as the caller.- Type Parameters:
- V- The type of the task's result, or- Voidif the task does not return anything (i.e. it only has side-effects).
- E- The type of the exception thrown by the task if it fails, or- NeverThrowsExceptionif the task cannot fail.
- Parameters:
- exception- The exception indicating why the asynchronous task has failed.
- Returns:
- A Promiserepresenting an asynchronous task which has already failed with the provided exception.
 
 - 
newResultPromisepublic static <V,E extends Exception> Promise<V,E> newResultPromise(V result) Returns aPromiserepresenting an asynchronous task which has already succeeded with the provided result. Attempts to get the result will immediately return the result, and any listeners registered against the returned promise will be immediately invoked in the same thread as the caller.- Type Parameters:
- V- The type of the task's result, or- Voidif the task does not return anything (i.e. it only has side-effects).
- E- The type of the exception thrown by the task if it fails, or- NeverThrowsExceptionif the task cannot fail.
- Parameters:
- result- The result of the asynchronous task.
- Returns:
- A Promiserepresenting an asynchronous task which has already succeeded with the provided result.
 
 - 
newVoidResultPromisepublic static <E extends Exception> Promise<Void,E> newVoidResultPromise() Returns aPromiserepresenting an asynchronous task which has already succeeded without result. Any listeners registered against the returned promise will be immediately invoked in the same thread as the caller.- Type Parameters:
- E- The type of the exception thrown by the task if it fails, or- NeverThrowsExceptionif the task cannot fail.
- Returns:
- A Promiserepresenting an asynchronous task which has already succeeded with the provided result.
 
 - 
whenpublic static <V,E extends Exception> Promise<List<V>,E> when(List<Promise<V,E>> promises) Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.- Type Parameters:
- V- The type of the tasks' result, or- Voidif the tasks do not return anything (i.e. they only has side-effects).
- E- The type of the exception thrown by the tasks if they fail, or- NeverThrowsExceptionif the tasks cannot fail.
- Parameters:
- promises- The list of tasks to be combined.
- Returns:
- A Promisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.
 
 - 
when@SafeVarargs public static <V,E extends Exception> Promise<List<V>,E> when(Promise<V,E>... promises) Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.- Type Parameters:
- V- The type of the tasks' result, or- Voidif the tasks do not return anything (i.e. they only has side-effects).
- E- The type of the exception thrown by the tasks if they fail, or- NeverThrowsExceptionif the tasks cannot fail.
- Parameters:
- promises- The list of tasks to be combined.
- Returns:
- A Promisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them has thrown an exception.
 
 - 
anyResultFrompublic static <V,E extends Exception> Optional<Promise<V,E>> anyResultFrom(Stream<Promise<V,E>> promises) Takes a stream of promises that may not yet be resolved and returns a resolved value from them, or if none resolve to a result, the failure from the last.- Type Parameters:
- V- The type of promise value.
- E- The type of promise exception.
- Parameters:
- promises- The promises.
- Returns:
- A promise that will either have a completed value from one of the provided promsies, or the failure from the last promise to complete, or an empty optional if there were no promises.
 
 - 
allDonepublic static Promise<Void,NeverThrowsException> allDone(Collection<Promise<?,?>> promises) Returns aPromisewhich will be completed successfully once all of the provided promises have completed (successfully or not, including runtime exceptions).- Parameters:
- promises- The collection of tasks to be combined.
- Returns:
- A Promisewhich will be completed successfully once all of the provided promises have completed (successfully or not).
 
 - 
allDonepublic static <V> Promise<V,NeverThrowsException> allDone(Collection<Promise<?,?>> promises, V context) Returns aPromisewhich will be completed successfully once all of the provided promises have completed (successfully or not, including runtime exceptions), returning back thecontextparameter.- Type Parameters:
- V- The type of the promise' result (can be- Void).
- Parameters:
- promises- The collection of tasks to be combined.
- context- Instance passed back to the resulting promise on completion (can be- null)
- Returns:
- A Promisewhich will be completed successfully once all of the provided promises have completed (successfully or not).
 
 - 
join@SafeVarargs public static Promise<Promises.Results,Exception> join(Promise<?,? extends Exception>... promises) Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.On successful completion, an immutable Promises.Resultsinstance containing all respective results of the joined promises (in the same order) is provided.- Parameters:
- promises- The list of tasks to be combined.
- Returns:
- A Promisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them has thrown an exception.
 
 - 
joinpublic static Promise<Promises.Results,Exception> join(List<Promise<?,? extends Exception>> promises) Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.On successful completion, an immutable Promises.Resultsinstance containing all respective results of the joined promises (in the same order) is provided.- Parameters:
- promises- The list of tasks to be combined.
- Returns:
- A Promisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them has thrown an exception.
 
 
- 
 
-