Package org.forgerock.util.promise
Class Promises
java.lang.Object
org.forgerock.util.promise.Promises
Utility methods for creating and composing
Promises.-
Method Summary
Modifier and TypeMethodDescriptionnewExceptionPromise(E exception) Returns aPromiserepresenting an asynchronous task which has already failed with the provided exception.newResultPromise(V result) Returns aPromiserepresenting an asynchronous task which has already succeeded with the provided result.newRuntimeExceptionPromise(RuntimeException exception) Returns aPromiserepresenting an asynchronous task which has already failed with the provided runtime exception.Returns aPromisewhich will be completed once all of the provided promises have succeeded, or as soon as one of them fails.Returns aPromisewhich 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 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, orVoidif 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, orNeverThrowsExceptionif 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.
-
newExceptionPromise
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, orVoidif 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, orNeverThrowsExceptionif 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.
-
newResultPromise
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, orVoidif 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, orNeverThrowsExceptionif 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.
-
when
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, orVoidif 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, orNeverThrowsExceptionif 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, orVoidif 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, orNeverThrowsExceptionif 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.
-