Package dev.restate.sdk
Class Awaitable<T>
- java.lang.Object
-
- dev.restate.sdk.Awaitable<T>
-
- Type Parameters:
T- type of the awaitable result
- Direct Known Subclasses:
AnyAwaitable,Awakeable
@NotThreadSafe public abstract class Awaitable<T> extends java.lang.ObjectAnAwaitableallows to await an asynchronous result. Onceawait()is called, the execution stops until the asynchronous result is available.The result can be either a success or a failure. In case of a failure,
await()will throw aTerminalException.
-
-
Field Summary
Fields Modifier and Type Field Description protected dev.restate.sdk.common.syscalls.Syscallssyscalls
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Awaitable<java.lang.Void>all(Awaitable<?> first, Awaitable<?> second, Awaitable<?>... others)Create anAwaitablethat awaits all the given awaitables.static AnyAwaitableany(Awaitable<?> first, Awaitable<?> second, Awaitable<?>... others)Create anAwaitablethat awaits any of the given awaitables.Tawait()Wait for the current awaitable to complete.Tawait(java.time.Duration timeout)protected abstract dev.restate.sdk.common.syscalls.Result<T>awaitResult()protected abstract dev.restate.sdk.common.syscalls.Deferred<?>deferred()<U> Awaitable<U>map(dev.restate.sdk.common.function.ThrowingFunction<T,U> mapper)Map the result of thisAwaitable.
-
-
-
Method Detail
-
deferred
protected abstract dev.restate.sdk.common.syscalls.Deferred<?> deferred()
-
awaitResult
protected abstract dev.restate.sdk.common.syscalls.Result<T> awaitResult()
-
await
public final T await() throws dev.restate.sdk.common.TerminalException
Wait for the current awaitable to complete. Executing this method may trigger the suspension of the function.NOTE: You should never wrap this invocation in a try-catch catching
RuntimeException, as it will catchAbortedExecutionExceptionas well.- Throws:
dev.restate.sdk.common.TerminalException- if the awaitable is ready and contains a failure
-
await
public final T await(java.time.Duration timeout) throws dev.restate.sdk.common.TerminalException, java.util.concurrent.TimeoutException
Same asawait(), but throws aTimeoutExceptionif thisAwaitabledoesn't complete before the providedtimeout.- Throws:
dev.restate.sdk.common.TerminalExceptionjava.util.concurrent.TimeoutException
-
map
public final <U> Awaitable<U> map(dev.restate.sdk.common.function.ThrowingFunction<T,U> mapper)
Map the result of thisAwaitable.
-
any
public static AnyAwaitable any(Awaitable<?> first, Awaitable<?> second, Awaitable<?>... others)
Create anAwaitablethat awaits any of the given awaitables.The behavior is the same as
CompletableFuture.anyOf(CompletableFuture[]).
-
-