Package dev.restate.sdk
Class Select<T>
java.lang.Object
dev.restate.sdk.DurableFuture<T>
dev.restate.sdk.Select<T>
- Type Parameters:
T
- the output value
Select lets you await concurrently for multiple
DurableFuture
s to complete, and for the
first one to complete, either return its value directly or map it.
Example:
// Using awakeables as example here
var a1 = ctx.awakeable(String.class);
var a2 = ctx.awakeable(MyObject.class);
var a3 = ctx.awakeable(String.class);
var result = Select.<String>select()
// Just select the a1 as is
.or(a1)
// When selecting a2, map the success result
.when(a2, myObject -> myObject.toString())
// When selecting a3, map failure as another failure
.when(a3, ThrowingFunction.identity(), ex -> {
throw new TerminalException("a3 failed, too bad!");
})
// Finally await for the result
.await();
-
Method Summary
Modifier and TypeMethodDescriptionprotected AsyncResult
<T> or
(DurableFuture<T> durableFuture) Add the givenDurableFuture
to this select.static <T> Select
<T> select()
Create a newSelect
operation.protected Executor
when
(DurableFuture<U> durableFuture, ThrowingFunction<U, T> successMapper) Add the givenDurableFuture
to this select.when
(DurableFuture<U> durableFuture, ThrowingFunction<U, T> successMapper, ThrowingFunction<TerminalException, T> failureMapper) Add the givenDurableFuture
to this select.Methods inherited from class dev.restate.sdk.DurableFuture
all, all, any, any, await, await, map, map, mapFailure, withTimeout
-
Method Details
-
select
Create a newSelect
operation.- Type Parameters:
T
- The return of the select.
-
or
Add the givenDurableFuture
to this select.- Returns:
- this, so it can be used fluently.
-
when
Add the givenDurableFuture
to this select. If it completes first, the success result will be mapped usingsuccessMapper
, otherwise in case ofTerminalException
, the exception will be thrown as is.- Parameters:
durableFuture
- theDurableFuture
to add to this selectsuccessMapper
- the mapper to execute if the givenDurableFuture
completes with success. The mapper can throw aTerminalException
, thus failing the resulting operation.- Returns:
- this, so it can be used fluently.
-
when
public <U> Select<T> when(DurableFuture<U> durableFuture, ThrowingFunction<U, T> successMapper, ThrowingFunction<TerminalException, T> failureMapper) Add the givenDurableFuture
to this select. If it completes first, the success result will be mapped usingsuccessMapper
, otherwise in case ofTerminalException
, the exception will be mapped usingfailureMapper
.- Parameters:
durableFuture
- theDurableFuture
to add to this selectsuccessMapper
- the mapper to execute if the givenDurableFuture
completes with success. The mapper can throw aTerminalException
, thus failing the resulting operation.failureMapper
- the mapper to execute if the givenDurableFuture
completes with failure. The mapper can throw aTerminalException
, thus failing the resulting operation.- Returns:
- this, so it can be used fluently.
-
asyncResult
- Specified by:
asyncResult
in classDurableFuture<T>
-
serviceExecutor
- Specified by:
serviceExecutor
in classDurableFuture<T>
-