You don't have to use .get()
.
In Promise, you can register a callback function to be invoked when the result is available or an error is returned.
You can use one of the below depends on what you need:
- thenApply
- handle
- thenCompose
- exceptionally
This style is similar to Java's CompletableFuture.
/**
* Returns Promise that contains a result of a function. The function is called with the value of
* this Promise when it is ready. #completeExceptionally is propagated directly to the returned
* Promise skipping the function.
*
* <p>Note that no blocking calls are allowed inside of the function.
*/
<U> Promise<U> thenApply(Functions.Func1<? super V, ? extends U> fn);
/**
* Returns Promise that contains a result of a function. The function is called with the value of
* this Promise or with an exception when it is completed. If the function throws a {@link
* RuntimeException} it fails the resulting promise.
*
* <p>Note that no blocking calls are allowed inside of the function.
*/
<U> Promise<U> handle(Functions.Func2<? super V, RuntimeException, ? extends U> fn);
/**
* Returns a new Promise that, when this promise completes normally, is executed with this promise
* as the argument to the supplied function.
*
* @param fn the function returning a new Promise
* @param <U> the type of the returned CompletionStage's result
* @return the Promise that completes when fn returned Promise completes.
*/
<U> Promise<U> thenCompose(Functions.Func1<? super V, ? extends Promise<U>> fn);
/**
* Returns a new Promise that, when this promise completes exceptionally, is executed with this
* promise's exception as the argument to the supplied function. Otherwise, if this promise
* completes normally, then the returned promise also completes normally with the same value.
*
* @param fn the function to use to compute the value of the returned CompletionPromise if this
* CompletionPromise completed exceptionally
* @return the new Promise
*/
Promise<V> exceptionally(Functions.Func1<Throwable, ? extends V> fn);