Package org.forgerock.util.promise
Class Promises
java.lang.Object
org.forgerock.util.promise.Promises
Utility methods for creating and composing
Promise
s.-
Method Summary
Modifier and TypeMethodDescriptionnewExceptionPromise
(E exception) Returns aPromise
representing an asynchronous task which has already failed with the provided exception.newResultPromise
(V result) Returns aPromise
representing an asynchronous task which has already succeeded with the provided result.newRuntimeExceptionPromise
(RuntimeException exception) Returns aPromise
representing an asynchronous task which has already failed with the provided runtime exception.Returns aPromise
which will be completed once all of the provided promises have succeeded, or as soon as one of them fails.Returns aPromise
which will be completed once all of the provided promises have succeeded, or as soon as one of them fails.
-
Method Details
-
newRuntimeExceptionPromise
public static <V,E extends Exception> Promise<V,E> newRuntimeExceptionPromise(RuntimeException exception) Returns aPromise
representing 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, orVoid
if 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, orNeverThrowsException
if the task cannot fail.- Parameters:
exception
- The exception indicating why the asynchronous task has failed.- Returns:
- A
Promise
representing an asynchronous task which has already failed with the provided exception.
-
newExceptionPromise
Returns aPromise
representing 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, orVoid
if 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, orNeverThrowsException
if the task cannot fail.- Parameters:
exception
- The exception indicating why the asynchronous task has failed.- Returns:
- A
Promise
representing an asynchronous task which has already failed with the provided exception.
-
newResultPromise
Returns aPromise
representing 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, orVoid
if 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, orNeverThrowsException
if the task cannot fail.- Parameters:
result
- The result of the asynchronous task.- Returns:
- A
Promise
representing an asynchronous task which has already succeeded with the provided result.
-
when
Returns aPromise
which 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, orVoid
if 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, orNeverThrowsException
if the tasks cannot fail.- Parameters:
promises
- The list of tasks to be combined.- Returns:
- A
Promise
which 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 aPromise
which 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, orVoid
if 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, orNeverThrowsException
if the tasks cannot fail.- Parameters:
promises
- The list of tasks to be combined.- Returns:
- A
Promise
which will be completed once all of the provided promises have succeeded, or as soon as one of them has thrown an exception.
-