Context

sealed interface Context

This interface exposes the Restate functionalities to Restate services. It can be used to interact with other Restate services, record non-deterministic closures, execute timers and synchronize with external systems.

All methods of this interface, and related interfaces, throws either TerminalException or cancels the coroutine. TerminalException can be caught and acted upon.

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

Inheritors

Functions

Link copied to clipboard
abstract suspend fun <T : Any> awakeable(typeTag: TypeTag<T>): Awakeable<T>

Create an Awakeable, addressable through Awakeable.id.

Link copied to clipboard
inline suspend fun <T : Any> Context.awakeable(): Awakeable<T>

Create an Awakeable, addressable through Awakeable.id.

Link copied to clipboard

Create a new AwakeableHandle for the provided identifier. You can use it to AwakeableHandle.resolve or AwakeableHandle.reject the linked Awakeable.

Link copied to clipboard
abstract suspend fun <Req, Res> call(request: Request<Req, Res>): CallDurableFuture<Res>

Invoke another Restate handler.

Link copied to clipboard
abstract fun <Res> invocationHandle(invocationId: String, responseTypeTag: TypeTag<Res>): InvocationHandle<Res>

Get an InvocationHandle for an already existing invocation. This will let you interact with a running invocation, for example to cancel it or retrieve its result.

Link copied to clipboard
inline fun <Res> Context.invocationHandle(invocationId: String): InvocationHandle<Res>

Get an InvocationHandle for an already existing invocation. This will let you interact with a running invocation, for example to cancel it or retrieve its result.

Link copied to clipboard
abstract fun random(): RestateRandom

Create a RestateRandom instance inherently predictable, seeded on the dev.restate.sdk.common.InvocationId, which is not secret.

Link copied to clipboard
abstract fun request(): HandlerRequest
Link copied to clipboard
abstract suspend fun <T> runAsync(typeTag: TypeTag<T>, name: String = "", retryPolicy: RetryPolicy? = null, block: suspend () -> T): DurableFuture<T>

Execute a closure asynchronously. This is like runBlock, but it returns a DurableFuture that you can combine and select.

Link copied to clipboard
inline suspend fun <T : Any> Context.runAsync(name: String = "", retryPolicy: RetryPolicy? = null, noinline block: suspend () -> T): DurableFuture<T>

Execute a closure asynchronously. This is like runBlock, but it returns a DurableFuture that you can combine and select.

Link copied to clipboard
open suspend fun <T> runBlock(typeTag: TypeTag<T>, name: String = "", retryPolicy: RetryPolicy? = null, block: suspend () -> T): T

Execute a closure, recording the result value in the journal. The result value will be re-played in case of re-invocation (e.g. because of failure recovery or suspension point) without re-executing the closure.

Link copied to clipboard
inline suspend fun <T : Any> Context.runBlock(name: String = "", retryPolicy: RetryPolicy? = null, noinline block: suspend () -> T): T

Execute a closure, recording the result value in the journal. The result value will be re-played in case of re-invocation (e.g. because of failure recovery or suspension point) without re-executing the closure.

Link copied to clipboard
abstract suspend fun <Req, Res> send(request: Request<Req, Res>, delay: Duration? = null): InvocationHandle<Res>

Invoke another Restate handler without waiting for the response.

Link copied to clipboard
open suspend fun sleep(duration: Duration)

Causes the current execution of the function invocation to sleep for the given duration.

Link copied to clipboard
abstract suspend fun timer(duration: Duration, name: String? = null): DurableFuture<Unit>

Causes the start of a timer for the given duration. You can await on the timer end by invoking DurableFuture.await.