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(serde: Serde<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 using KtSerdes.json deserializer, 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
open suspend fun <T, R> call(target: Target, inputSerde: Serde<T>, outputSerde: Serde<R>, parameter: T): R

Invoke another Restate service method and wait for the response. Same as call(methodDescriptor, parameter).await().

Link copied to clipboard
abstract suspend fun <T, R> callAsync(target: Target, inputSerde: Serde<T>, outputSerde: Serde<R>, parameter: T): Awaitable<R>

Invoke another Restate service method.

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(): Request
Link copied to clipboard
abstract suspend fun <T> runBlock(serde: Serde<T>, name: String = "", block: suspend () -> T): T

Execute a non-deterministic 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. Use this feature if you want to perform non-deterministic operations.

abstract suspend fun <T> runBlock(serde: Serde<T>, name: String = "", retryPolicy: RetryPolicy? = null, block: suspend () -> T): T

Like runBlock, but using a custom retry policy.

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

Execute a non-deterministic closure, recording the result value in the journal using KtSerdes.json. 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. Use this feature if you want to perform non-deterministic operations.

inline suspend fun <T : Any> Context.runBlock(name: String = "", retryPolicy: RetryPolicy? = null, noinline block: suspend () -> T): T
Link copied to clipboard
abstract suspend fun <T> send(target: Target, inputSerde: Serde<T>, parameter: T, delay: Duration = Duration.ZERO)

Invoke another Restate service 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): Awaitable<Unit>

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