Class PromiseImpl<V,E extends Exception>
- java.lang.Object
- 
- org.forgerock.util.promise.PromiseImpl<V,E>
 
- 
- 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.
 - All Implemented Interfaces:
- ExceptionHandler<E>,- Promise<V,E>,- ResultHandler<V>,- RuntimeExceptionHandler
 
 public class PromiseImpl<V,E extends Exception> extends Object implements Promise<V,E>, ResultHandler<V>, ExceptionHandler<E>, RuntimeExceptionHandler An implementation ofPromisewhich can be used as is, or as the basis for more complex asynchronous behavior. APromiseImplmust be completed by invoking one of:- handleResult(V)- marks the promise as having succeeded with the provide result
- handleException(E)- marks the promise as having failed with the provided exception
- cancel(boolean)- requests cancellation of the asynchronous task represented by the promise. Cancellation is only supported if the- tryCancel(boolean)is overridden and returns an exception.
 
- 
- 
Constructor SummaryConstructors Modifier Constructor Description protectedPromiseImpl()Creates a new pendingPromiseimplementation.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)Attempts to cancel the asynchronous task associated with thisPromise.static <V,E extends Exception>
 PromiseImpl<V,E>create()Creates a new pendingPromiseimplementation.Vget()Waits if necessary for thisPromiseto complete, and then returns the result if it completed successfully, or throws anExecutionExceptioncontaining the cause of the failure.Vget(long timeout, TimeUnit unit)Waits if necessary for at most the given time for thisPromiseto complete, and then returns the result if it completed successfully, or throws anExecutionExceptioncontaining the cause of the failure.VgetOrThrow()Waits if necessary for thisPromiseto complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.VgetOrThrow(long timeout, TimeUnit unit)Waits if necessary for at most the given time for thisPromiseto complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.VgetOrThrowUninterruptibly()Deprecated.VgetOrThrowUninterruptibly(long timeout, TimeUnit unit)Deprecated.voidhandleException(E exception)Signals that the asynchronous task represented by this promise has failed.voidhandleResult(V result)Signals that the asynchronous task represented by this promise has succeeded.voidhandleRuntimeException(RuntimeException exception)Invoked when the asynchronous task has failed with a runtime exception.booleanisCancelled()Returnstrueif thisPromisewas cancelled before it completed normally.booleanisDone()Returnstrueif thisPromisehas completed.booleanisResult()Returnstrueif thisPromisehas completed and contains a value.<VOUT> Promise<VOUT,E>then(Function<? super V,VOUT,E> onResult)Submits the provided function for execution once thisPromisehas completed with a result, and returns a newPromiserepresenting the outcome of the function.<VOUT,EOUT extends Exception>
 Promise<VOUT,EOUT>then(Function<? super V,VOUT,EOUT> onResult, Function<? super E,VOUT,EOUT> onException)Submits the provided functions for execution once thisPromisehas completed (with a result or an exception), and returns a newPromiserepresenting the outcome of the invoked function.<VOUT,EOUT extends Exception>
 Promise<VOUT,EOUT>then(Function<? super V,VOUT,EOUT> onResult, Function<? super E,VOUT,EOUT> onException, Function<? super RuntimeException,VOUT,EOUT> onRuntimeException)Submits the provided functions for execution once thisPromisehas completed (with a result or an exception or aRuntimeException), and returns a newPromiserepresenting the outcome of the invoked function.Promise<V,E>thenAlways(Runnable always)Submits the provided runnable for execution once thisPromisehas completed, and regardless of whether it has a result or an exception.<VOUT> Promise<VOUT,E>thenAsync(AsyncFunction<? super V,VOUT,E> onResult)Submits the provided asynchronous function for execution once thisPromisehas completed with a result, and returns a newPromiserepresenting the outcome of the function.<VOUT,EOUT extends Exception>
 Promise<VOUT,EOUT>thenAsync(AsyncFunction<? super V,VOUT,EOUT> onResult, AsyncFunction<? super E,VOUT,EOUT> onException)Submits the provided asynchronous functions for execution once thisPromisehas completed, and returns a newPromiserepresenting the outcome of the invoked function.<VOUT,EOUT extends Exception>
 Promise<VOUT,EOUT>thenAsync(AsyncFunction<? super V,VOUT,EOUT> onResult, AsyncFunction<? super E,VOUT,EOUT> onException, AsyncFunction<? super RuntimeException,VOUT,EOUT> onRuntimeException)Submits the provided asynchronous functions for execution once thisPromisehas completed, and returns a newPromiserepresenting the outcome of the invoked function.<EOUT extends Exception>
 Promise<V,EOUT>thenCatch(Function<? super E,V,EOUT> onException)Submits the provided function for execution once thisPromisehas not completed with a result (has completed with an exception), and returns a newPromiserepresenting the outcome of the function.<EOUT extends Exception>
 Promise<V,EOUT>thenCatchAsync(AsyncFunction<? super E,V,EOUT> onException)Submits the provided asynchronous function for execution once thisPromisehas completed with an exception, and returns a newPromiserepresenting the outcome of the function.Promise<V,E>thenCatchRuntimeException(Function<? super RuntimeException,V,E> onRuntimeException)Submits the provided function for execution once thisPromisehas not completed with a result nor with an exception but with aRuntimeException, and returns a newPromiserepresenting the outcome of the function.Promise<V,E>thenCatchRuntimeExceptionAsync(AsyncFunction<? super RuntimeException,V,E> onRuntimeException)Submits the provided asynchronous function for execution once thisPromisehas completed with aRuntimeException, and returns a newPromiserepresenting the outcome of the function.Promise<V,E>thenFinally(Runnable onFinally)Submits the provided runnable for execution once thisPromisehas completed, and regardless of whether of its outcome.<T extends ResultHandler<? super V> & ExceptionHandler<? super E> & RuntimeExceptionHandler>
 Promise<V,E>thenOnCompletion(T handler)Registers the provided completion handler for notification for all completion cases of thisPromise.Promise<V,E>thenOnException(ExceptionHandler<? super E> onException)Registers the provided completion handler for notification if thisPromisecannot be completed due to an exception.Promise<V,E>thenOnResult(ResultHandler<? super V> onResult)Registers the provided completion handler for notification once thisPromisehas completed with a result.Promise<V,E>thenOnResultOrException(Runnable onResultOrException)Submits the provided runnable for execution once thisPromisehas completed, and regardless of whether it has a result or an exception.Promise<V,E>thenOnResultOrException(ResultHandler<? super V> onResult, ExceptionHandler<? super E> onException)Registers the provided completion handlers for notification once thisPromisehas completed (with a result or an exception).Promise<V,E>thenOnRuntimeException(RuntimeExceptionHandler onRuntimeException)Registers the provided completion handler for notification if thisPromisecannot be completed due to an runtime exception.protected EtryCancel(boolean mayInterruptIfRunning)Invoked when the client attempts to cancel the asynchronous task represented by this promise.booleantryHandleException(E exception)Attempts to signal that the asynchronous task represented by this promise has failed.booleantryHandleResult(V result)Attempts to signal that the asynchronous task represented by this promise has succeeded.- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.forgerock.util.promise.PromisegetOrThrowIfInterrupted, thenDiscardResult
 
- 
 
- 
- 
- 
Constructor Detail- 
PromiseImplprotected PromiseImpl() Creates a new pendingPromiseimplementation. This constructor is protected to allow for sub-classing.
 
- 
 - 
Method Detail- 
createpublic static <V,E extends Exception> PromiseImpl<V,E> create() Creates a new pendingPromiseimplementation.- 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.
- Returns:
- A new pending Promiseimplementation.
 
 - 
cancelpublic final boolean cancel(boolean mayInterruptIfRunning) Description copied from interface:PromiseAttempts to cancel the asynchronous task associated with thisPromise. Cancellation will fail if thisPromisehas already completed or has already been cancelled. If successful, then cancellation will complete thisPromisewith an appropriate exception and notify any registered functions and completion handlers.After this method returns, subsequent calls to Promise.isDone()will always returntrue. Subsequent calls toPromise.isCancelled()will always returntrueif this method returnedtrue.- Specified by:
- cancelin interface- Promise<V,E extends Exception>
- Parameters:
- mayInterruptIfRunning-- trueif the thread executing executing the response handler should be interrupted; otherwise, in-progress response handlers are allowed to complete.
- Returns:
- falseif- Promisecould not be cancelled, typically because it has already completed normally;- trueotherwise.
 
 - 
getpublic final V get() throws InterruptedException, ExecutionException Description copied from interface:PromiseWaits if necessary for thisPromiseto complete, and then returns the result if it completed successfully, or throws anExecutionExceptioncontaining the cause of the failure.- Specified by:
- getin interface- Promise<V,E extends Exception>
- Returns:
- The result, but only if this Promisecompleted successfully.
- Throws:
- InterruptedException- If the current thread was interrupted while waiting.
- ExecutionException- If this- Promisewas cancelled or did not complete successfully. The- ExecutionExceptionwill contain the cause of the failure.
 
 - 
getpublic final V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Description copied from interface:PromiseWaits if necessary for at most the given time for thisPromiseto complete, and then returns the result if it completed successfully, or throws anExecutionExceptioncontaining the cause of the failure.- Specified by:
- getin interface- Promise<V,E extends Exception>
- Parameters:
- timeout- The maximum time to wait.
- unit- The time unit of the timeout argument.
- Returns:
- The result, but only if this Promisecompleted successfully.
- Throws:
- InterruptedException- If the current thread was interrupted while waiting.
- ExecutionException- If this- Promisewas cancelled or did not complete successfully. The- ExecutionExceptionwill contain the cause of the failure.
- TimeoutException- If the wait timed out.
 
 - 
getOrThrowpublic final V getOrThrow() throws InterruptedException, E extends Exception Description copied from interface:PromiseWaits if necessary for thisPromiseto complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.- Specified by:
- getOrThrowin interface- Promise<V,E extends Exception>
- Returns:
- The result, but only if this Promisecompleted successfully.
- Throws:
- InterruptedException- If the current thread was interrupted while waiting.
- E- If this- Promisewas cancelled or did not complete successfully.
- E extends Exception
 
 - 
getOrThrowpublic final V getOrThrow(long timeout, TimeUnit unit) throws InterruptedException, E extends Exception, TimeoutException Description copied from interface:PromiseWaits if necessary for at most the given time for thisPromiseto complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.- Specified by:
- getOrThrowin interface- Promise<V,E extends Exception>
- Parameters:
- timeout- The maximum time to wait.
- unit- The time unit of the timeout argument.
- Returns:
- The result, but only if this Promisecompleted successfully.
- Throws:
- InterruptedException- If the current thread was interrupted while waiting.
- E- If this- Promisewas cancelled or did not complete successfully.
- TimeoutException- If the wait timed out.
- E extends Exception
 
 - 
getOrThrowUninterruptibly@Deprecated public final V getOrThrowUninterruptibly() throws E extends Exception Deprecated.Description copied from interface:PromiseWaits if necessary for thisPromiseto complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.This method is similar to Promise.getOrThrow()except that it will ignore thread interrupts. When this method returns the status of the current thread will be interrupted if an interrupt was received while waiting.
 - 
getOrThrowUninterruptibly@Deprecated public final V getOrThrowUninterruptibly(long timeout, TimeUnit unit) throws E extends Exception, TimeoutException Deprecated.Description copied from interface:PromiseWaits if necessary for at most the given time for thisPromiseto complete, and then returns the result if it completed successfully, or throws an exception representing the cause of the failure.This method is similar to Promise.getOrThrow(long, TimeUnit)except that it will ignore thread interrupts. When this method returns the status of the current thread will be interrupted if an interrupt was received while waiting.- Specified by:
- getOrThrowUninterruptiblyin interface- Promise<V,E extends Exception>
- Parameters:
- timeout- The maximum time to wait.
- unit- The time unit of the timeout argument.
- Returns:
- The result, but only if this Promisecompleted successfully.
- Throws:
- E- If this- Promisewas cancelled or did not complete successfully.
- TimeoutException- If the wait timed out.
- E extends Exception
 
 - 
handleExceptionpublic final void handleException(E exception) Signals that the asynchronous task represented by this promise has failed. If the task has already completed (i.e.isDone() == true) then calling this method has no effect and the provided result will be discarded.- Specified by:
- handleExceptionin interface- ExceptionHandler<V>
- Parameters:
- exception- The exception indicating why the task failed.
- See Also:
- tryHandleException(Exception)
 
 - 
handleRuntimeExceptionpublic void handleRuntimeException(RuntimeException exception) Description copied from interface:RuntimeExceptionHandlerInvoked when the asynchronous task has failed with a runtime exception.- Specified by:
- handleRuntimeExceptionin interface- RuntimeExceptionHandler
- Parameters:
- exception- The runtime exception indicating why the asynchronous task has failed.
 
 - 
handleResultpublic final void handleResult(V result) Signals that the asynchronous task represented by this promise has succeeded. If the task has already completed (i.e.isDone() == true) then calling this method has no effect and the provided result will be discarded.- Specified by:
- handleResultin interface- ResultHandler<V>
- Parameters:
- result- The result of the asynchronous task (may be- null).
- See Also:
- tryHandleResult(Object)
 
 - 
tryHandleExceptionpublic final boolean tryHandleException(E exception) Attempts to signal that the asynchronous task represented by this promise has failed. If the task has already completed (i.e.isDone() == true) then calling this method has no effect andfalseis returned.This method should be used in cases where multiple threads may concurrently attempt to complete a promise and need to release resources if the completion attempt fails. For example, an asynchronous TCP connect attempt may complete after a timeout has expired. In this case the connection should be immediately closed because it is never going to be used. - Parameters:
- exception- The exception indicating why the task failed.
- Returns:
- falseif this promise has already been completed, either due to normal termination, an exception, or cancellation (i.e.- isDone() == true).
- See Also:
- handleException(Exception),- isDone()
 
 - 
tryHandleResultpublic final boolean tryHandleResult(V result) Attempts to signal that the asynchronous task represented by this promise has succeeded. If the task has already completed (i.e.isDone() == true) then calling this method has no effect andfalseis returned.This method should be used in cases where multiple threads may concurrently attempt to complete a promise and need to release resources if the completion attempt fails. For example, an asynchronous TCP connect attempt may complete after a timeout has expired. In this case the connection should be immediately closed because it is never going to be used. - Parameters:
- result- The result of the asynchronous task (may be- null).
- Returns:
- falseif this promise has already been completed, either due to normal termination, an exception, or cancellation (i.e.- isDone() == true).
- See Also:
- handleResult(Object),- isDone()
 
 - 
isCancelledpublic final boolean isCancelled() Description copied from interface:PromiseReturnstrueif thisPromisewas cancelled before it completed normally.- Specified by:
- isCancelledin interface- Promise<V,E extends Exception>
- Returns:
- trueif this- Promisewas cancelled before it completed normally, otherwise- false.
 
 - 
isDonepublic final boolean isDone() Description copied from interface:PromiseReturnstrueif thisPromisehas completed.Completion may be due to normal termination, an exception, or cancellation. In all of these cases, this method will return true.
 - 
isResultpublic final boolean isResult() Description copied from interface:PromiseReturnstrueif thisPromisehas completed and contains a value.
 - 
thenOnExceptionpublic final Promise<V,E> thenOnException(ExceptionHandler<? super E> onException) Description copied from interface:PromiseRegisters the provided completion handler for notification if thisPromisecannot be completed due to an exception. If thisPromisecompletes with a result then the completion handler will not be notified.This method can be used for asynchronous completion notification. - Specified by:
- thenOnExceptionin interface- Promise<V,E extends Exception>
- Parameters:
- onException- The completion handler which will be notified upon failure completion of this- Promise.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
thenOnResultpublic final Promise<V,E> thenOnResult(ResultHandler<? super V> onResult) Description copied from interface:PromiseRegisters the provided completion handler for notification once thisPromisehas completed with a result. If thisPromisecompletes with an exception then the completion handler will not be notified.This method can be used for asynchronous completion notification and is equivalent to Promise.then(Function).- Specified by:
- thenOnResultin interface- Promise<V,E extends Exception>
- Parameters:
- onResult- The completion handler which will be notified upon successful completion of this- Promise.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
thenOnResultOrExceptionpublic final Promise<V,E> thenOnResultOrException(ResultHandler<? super V> onResult, ExceptionHandler<? super E> onException) Description copied from interface:PromiseRegisters the provided completion handlers for notification once thisPromisehas completed (with a result or an exception). If thisPromisecompletes with a result thenonResultwill be notified with the result, otherwiseonExceptionwill be notified with the exception that occurred.This method can be used for asynchronous completion notification. - Specified by:
- thenOnResultOrExceptionin interface- Promise<V,E extends Exception>
- Parameters:
- onResult- The completion handler which will be notified upon completion with a result of this- Promise.
- onException- The completion handler which will be notified upon failure of this- Promise.
- Returns:
- A Promisethat is guaranted to be completed once the provided callback has been executed.
 
 - 
thenOnResultOrExceptionpublic final Promise<V,E> thenOnResultOrException(Runnable onResultOrException) Description copied from interface:PromiseSubmits the provided runnable for execution once thisPromisehas completed, and regardless of whether it has a result or an exception.This method can be used for resource cleanup after a series of asynchronous tasks have completed. More specifically, this method should be used in a similar manner to finallystatements intry...catchexpressions.This method is equivalent to Promise.thenAlways(Runnable).- Specified by:
- thenOnResultOrExceptionin interface- Promise<V,E extends Exception>
- Parameters:
- onResultOrException- The runnable which will be notified regardless of the final outcome of this- Promise.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
thenpublic final <VOUT> Promise<VOUT,E> then(Function<? super V,VOUT,E> onResult) Description copied from interface:PromiseSubmits the provided function for execution once thisPromisehas completed with a result, and returns a newPromiserepresenting the outcome of the function. If thisPromisedoes not complete with a result then the function will not be invoked and the exception will be forwarded to the returnedPromise.This method can be used for transforming the result of an asynchronous task. - Specified by:
- thenin interface- Promise<V,E extends Exception>
- Type Parameters:
- VOUT- The type of the function's result, or- Voidif the function does not return anything (i.e. it only has side-effects). Note that the type may be different to the type of this- Promise.
- Parameters:
- onResult- The function which will be executed upon successful completion of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the function.
 
 - 
thenCatchpublic <EOUT extends Exception> Promise<V,EOUT> thenCatch(Function<? super E,V,EOUT> onException) Description copied from interface:PromiseSubmits the provided function for execution once thisPromisehas not completed with a result (has completed with an exception), and returns a newPromiserepresenting the outcome of the function. If thisPromisecompletes with a result then the function will not be invoked and the result notification will be forwarded to the returnedPromise.This method can be used for transforming the result of an asynchronous task. - Specified by:
- thenCatchin interface- Promise<V,E extends Exception>
- Type Parameters:
- EOUT- The type of the exception thrown by the function if it fails, or- NeverThrowsExceptionif it cannot fails. Note that the type may be different to the type of this- Promise.
- Parameters:
- onException- The function which will be executed upon failure completion of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the function.
 
 - 
thenCatchRuntimeExceptionpublic Promise<V,E> thenCatchRuntimeException(Function<? super RuntimeException,V,E> onRuntimeException) Description copied from interface:PromiseSubmits the provided function for execution once thisPromisehas not completed with a result nor with an exception but with aRuntimeException, and returns a newPromiserepresenting the outcome of the function. If thisPromisecompletes with a result or an exception then the function will not be invoked and the result notification will be forwarded to the returnedPromise.This method can be used for transforming the result of an asynchronous task. - Specified by:
- thenCatchRuntimeExceptionin interface- Promise<V,E extends Exception>
- Parameters:
- onRuntimeException- The function which will be executed upon failure completion of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the function.
 
 - 
thenpublic final <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> then(Function<? super V,VOUT,EOUT> onResult, Function<? super E,VOUT,EOUT> onException) Description copied from interface:PromiseSubmits the provided functions for execution once thisPromisehas completed (with a result or an exception), and returns a newPromiserepresenting the outcome of the invoked function. If thisPromisecompletes with a result thenonResultwill be invoked with the result, otherwiseonExceptionwill be invoked with the exception that occurred.This method can be used for transforming the outcome of an asynchronous task. - Specified by:
- thenin interface- Promise<V,E extends Exception>
- Type Parameters:
- VOUT- The type of the functions' result, or- Voidif the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of this- Promise.
- EOUT- The type of the exception thrown by the functions if they fail, or- NeverThrowsExceptionif they cannot fail. Note that the type may be different to the type of this- Promise.
- Parameters:
- onResult- The function which will be executed upon successful completion of this- Promise.
- onException- The function which will be executed upon failure of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the invoked function.
 
 - 
thenpublic final <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> then(Function<? super V,VOUT,EOUT> onResult, Function<? super E,VOUT,EOUT> onException, Function<? super RuntimeException,VOUT,EOUT> onRuntimeException) Description copied from interface:PromiseSubmits the provided functions for execution once thisPromisehas completed (with a result or an exception or aRuntimeException), and returns a newPromiserepresenting the outcome of the invoked function. If thisPromisecompletes with a result thenonResultwill be invoked with the result, with aRuntimeExceptionthenonRuntimeExceptionwill be invoked with the runtime exception that occurred, otherwiseonExceptionwill be invoked with the exception that occurred.This method can be used for transforming the outcome of an asynchronous task. - Specified by:
- thenin interface- Promise<V,E extends Exception>
- Type Parameters:
- VOUT- The type of the functions' result, or- Voidif the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of this- Promise.
- EOUT- The type of the exception thrown by the functions if they fail, or- NeverThrowsExceptionif they cannot fail. Note that the type may be different to the type of this- Promise.
- Parameters:
- onResult- The function which will be executed upon successful completion of this- Promise.
- onException- The function which will be executed upon failure of this- Promise.
- onRuntimeException- The function which will be executed upon failure with- RuntimeExceptionof this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the invoked function.
 
 - 
thenAlwayspublic final Promise<V,E> thenAlways(Runnable always) Description copied from interface:PromiseSubmits the provided runnable for execution once thisPromisehas completed, and regardless of whether it has a result or an exception.This method can be used for resource cleanup after a series of asynchronous tasks have completed. More specifically, this method should be used in a similar manner to finallystatements intry...catchexpressions.This method is equivalent to Promise.thenOnResultOrException(Runnable).- Specified by:
- thenAlwaysin interface- Promise<V,E extends Exception>
- Parameters:
- always- The runnable which will be notified regardless of the final outcome of this- Promise.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
thenFinallypublic final Promise<V,E> thenFinally(Runnable onFinally) Description copied from interface:PromiseSubmits the provided runnable for execution once thisPromisehas completed, and regardless of whether of its outcome.This method can be used for resource cleanup after a series of asynchronous tasks have completed. More specifically, this method should be used in a similar manner to finallystatements intry...catchexpressions.This method is equivalent to Promise.thenAlways(Runnable).- Specified by:
- thenFinallyin interface- Promise<V,E extends Exception>
- Parameters:
- onFinally- The runnable which will be notified regardless of the final outcome of this- Promise.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
thenAsyncpublic final <VOUT> Promise<VOUT,E> thenAsync(AsyncFunction<? super V,VOUT,E> onResult) Description copied from interface:PromiseSubmits the provided asynchronous function for execution once thisPromisehas completed with a result, and returns a newPromiserepresenting the outcome of the function. If thisPromisecomplete with an exception then the function will not be invoked and the error will be forwarded to the returnedPromise.This method may be used for chaining together a series of asynchronous tasks. - Specified by:
- thenAsyncin interface- Promise<V,E extends Exception>
- Type Parameters:
- VOUT- The type of the function's result, or- Voidif the function does not return anything (i.e. it only has side-effects). Note that the type may be different to the type of this- Promise.
- Parameters:
- onResult- The asynchronous function which will be executed upon successful completion of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the function.
 
 - 
thenCatchAsyncpublic final <EOUT extends Exception> Promise<V,EOUT> thenCatchAsync(AsyncFunction<? super E,V,EOUT> onException) Description copied from interface:PromiseSubmits the provided asynchronous function for execution once thisPromisehas completed with an exception, and returns a newPromiserepresenting the outcome of the function. If thisPromisecompletes with a result then the function will not be invoked and the exception will be forwarded to the returnedPromise.This method may be used for chaining together a series of asynchronous tasks. - Specified by:
- thenCatchAsyncin interface- Promise<V,E extends Exception>
- Type Parameters:
- EOUT- The type of the exception thrown by the function if it fails, or- NeverThrowsExceptionif it cannot fails. Note that the type may be different to the type of this- Promise.
- Parameters:
- onException- The asynchronous function which will be executed upon failure completion of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the function.
 
 - 
thenCatchRuntimeExceptionAsyncpublic final Promise<V,E> thenCatchRuntimeExceptionAsync(AsyncFunction<? super RuntimeException,V,E> onRuntimeException) Description copied from interface:PromiseSubmits the provided asynchronous function for execution once thisPromisehas completed with aRuntimeException, and returns a newPromiserepresenting the outcome of the function. If thisPromisecompletes with a result or the typed exception then the completion asynchronous function will not be called.This method may be used for chaining together a series of asynchronous tasks. - Specified by:
- thenCatchRuntimeExceptionAsyncin interface- Promise<V,E extends Exception>
- Parameters:
- onRuntimeException- The asynchronous function which will be executed upon failure completion with a- RuntimeExceptionof this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the function.
 
 - 
thenAsyncpublic final <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> thenAsync(AsyncFunction<? super V,VOUT,EOUT> onResult, AsyncFunction<? super E,VOUT,EOUT> onException) Description copied from interface:PromiseSubmits the provided asynchronous functions for execution once thisPromisehas completed, and returns a newPromiserepresenting the outcome of the invoked function. If thisPromisecompletes with a result thenonResultwill be invoked with the result, otherwiseonExceptionwill be invoked with the exception that occurred.This method may be used for chaining together a series of asynchronous tasks. - Specified by:
- thenAsyncin interface- Promise<V,E extends Exception>
- Type Parameters:
- VOUT- The type of the functions' result, or- Voidif the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of this- Promise.
- EOUT- The type of the exception thrown by the functions if they fail, or- NeverThrowsExceptionif they cannot fail. Note that the type may be different to the type of this- Promise.
- Parameters:
- onResult- The asynchronous function which will be executed upon successful completion of this- Promise.
- onException- The asynchronous function which will be executed upon failure of this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the invoked function.
 
 - 
thenAsyncpublic final <VOUT,EOUT extends Exception> Promise<VOUT,EOUT> thenAsync(AsyncFunction<? super V,VOUT,EOUT> onResult, AsyncFunction<? super E,VOUT,EOUT> onException, AsyncFunction<? super RuntimeException,VOUT,EOUT> onRuntimeException) Description copied from interface:PromiseSubmits the provided asynchronous functions for execution once thisPromisehas completed, and returns a newPromiserepresenting the outcome of the invoked function. If thisPromisecompletes with a result thenonResultwill be invoked with the result, otherwiseonExceptionwill be invoked with the exception that occurred, oronRuntimeExceptionwill be invoked with the runtime exception that occurred.This method may be used for chaining together a series of asynchronous tasks. - Specified by:
- thenAsyncin interface- Promise<V,E extends Exception>
- Type Parameters:
- VOUT- The type of the functions' result, or- Voidif the functions do not return anything (i.e. they only have side-effects). Note that the type may be different to the type of this- Promise.
- EOUT- The type of the exception thrown by the functions if they fail, or- NeverThrowsExceptionif they cannot fail. Note that the type may be different to the type of this- Promise.
- Parameters:
- onResult- The asynchronous function which will be executed upon successful completion of this- Promise.
- onException- The asynchronous function which will be executed upon failure of this- Promise.
- onRuntimeException- The asynchronous function which will be executed upon failure with- RuntimeExceptionof this- Promise.
- Returns:
- A new Promiserepresenting the outcome of the invoked function.
 
 - 
thenOnRuntimeExceptionpublic final Promise<V,E> thenOnRuntimeException(RuntimeExceptionHandler onRuntimeException) Description copied from interface:PromiseRegisters the provided completion handler for notification if thisPromisecannot be completed due to an runtime exception. If thisPromisecompletes with a result or the typed exception then the completion handler will not be notified.This method can be used for asynchronous completion notification. - Specified by:
- thenOnRuntimeExceptionin interface- Promise<V,E extends Exception>
- Parameters:
- onRuntimeException- The completion handler which will be notified upon an uncaught runtime exception completion of this- Promise.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
thenOnCompletionpublic final <T extends ResultHandler<? super V> & ExceptionHandler<? super E> & RuntimeExceptionHandler> Promise<V,E> thenOnCompletion(T handler) Description copied from interface:PromiseRegisters the provided completion handler for notification for all completion cases of thisPromise.This method can be used for asynchronous completion notification. - Specified by:
- thenOnCompletionin interface- Promise<V,E extends Exception>
- Type Parameters:
- T- the composite type of the handler for handling all completion cases
- Parameters:
- handler- The handler that will be called once this- Promiseis completed.
- Returns:
- A Promisethat is guaranteed to be completed once the provided callback has been executed.
 
 - 
tryCancelprotected E tryCancel(boolean mayInterruptIfRunning) Invoked when the client attempts to cancel the asynchronous task represented by this promise. Implementations which support cancellation should override this method to cancel the asynchronous task and, if successful, return an appropriate exception which can be used to signal that the task has failed.By default cancellation is not supported and this method returns null.- Parameters:
- mayInterruptIfRunning-- trueif the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete.
- Returns:
- nullif cancellation was not supported or not possible, otherwise an appropriate exception.
 
 
- 
 
-