Class Awaitable<T>

  • Type Parameters:
    T - type of the awaitable result
    Direct Known Subclasses:
    AnyAwaitable, Awakeable

    public abstract class Awaitable<T>
    extends java.lang.Object
    An Awaitable allows to await an asynchronous result. Once await() 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 a TerminalException.

    NOTE: This interface MUST NOT be accessed concurrently since it can lead to different orderings of user actions, corrupting the execution of the invocation.

    • Field Detail

      • syscalls

        protected final dev.restate.sdk.common.syscalls.Syscalls syscalls
    • 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 catch AbortedExecutionException as 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 as await(), but throws a TimeoutException if this Awaitable doesn't complete before the provided timeout.
        Throws:
        dev.restate.sdk.common.TerminalException
        java.util.concurrent.TimeoutException
      • map

        public final <U> Awaitable<U> map​(dev.restate.sdk.common.function.ThrowingFunction<T,​U> mapper)
        Map the result of this Awaitable.
      • any

        public static AnyAwaitable any​(Awaitable<?> first,
                                       Awaitable<?> second,
                                       Awaitable<?>... others)
        Create an Awaitable that awaits any of the given awaitables.

        The behavior is the same as CompletableFuture.anyOf(CompletableFuture[]).

      • any

        public static AnyAwaitable any​(java.util.List<Awaitable<?>> awaitables)
        Create an Awaitable that awaits any of the given awaitables.

        An empty list is not supported and will throw IllegalArgumentException.

        The behavior is the same as CompletableFuture.anyOf(CompletableFuture[]).

      • all

        public static Awaitable<java.lang.Void> all​(Awaitable<?> first,
                                                    Awaitable<?> second,
                                                    Awaitable<?>... others)
        Create an Awaitable that awaits all the given awaitables.

        The behavior is the same as CompletableFuture.allOf(CompletableFuture[]).

      • all

        public static Awaitable<java.lang.Void> all​(java.util.List<Awaitable<?>> awaitables)
        Create an Awaitable that awaits all the given awaitables.

        An empty list is not supported and will throw IllegalArgumentException.

        The behavior is the same as CompletableFuture.allOf(CompletableFuture[]).