Table of Contents

Interface IContext

Namespace
Restate.Sdk
Assembly
Restate.Sdk.dll

Interface exposing durable execution primitives available to all handler types. Use this for utility methods, type constraints, and testing with mocking frameworks. Handlers receive the abstract Context class; use Mock*Context classes for handler testing.

public interface IContext

Properties

Aborted

Cancellation token that fires when the invocation is aborted.

CancellationToken Aborted { get; }

Property Value

CancellationToken

Headers

Request headers from the original invocation.

IReadOnlyDictionary<string, string> Headers { get; }

Property Value

IReadOnlyDictionary<string, string>

InvocationId

Unique identifier of the current invocation.

string InvocationId { get; }

Property Value

string

Logger

Logger scoped to the current invocation. Output is suppressed while the invocation replays journal entries, so re-executed handler code does not log duplicate lines. Defaults to Instance so external IContext implementations keep compiling — mirroring Logger.

ILogger Logger { get; }

Property Value

ILogger

Methods

Attach<T>(string)

Attaches to a running invocation and awaits its result.

ValueTask<T> Attach<T>(string invocationId)

Parameters

invocationId string

Returns

ValueTask<T>

Type Parameters

T

Awakeable<T>(ISerde<T>?)

Creates a durable promise that can be resolved from outside the current invocation.

Awakeable<T> Awakeable<T>(ISerde<T>? serde = null)

Parameters

serde ISerde<T>

Returns

Awakeable<T>

Type Parameters

T

CallFuture<TResponse>(string, string, object?)

Calls a handler and returns a non-blocking future instead of awaiting the result.

IDurableFuture<TResponse> CallFuture<TResponse>(string service, string handler, object? request = null)

Parameters

service string
handler string
request object

Returns

IDurableFuture<TResponse>

Type Parameters

TResponse

CallFuture<TResponse>(string, string, object?, CallOptions)

Calls a handler with call options (idempotency key, scope, limit key) and returns a non-blocking future. Defaulted so that external implementations keep compiling: a scope or limit key is reported rather than dropped, and anything else falls through to the option-less overload. No option-less future overload carries an idempotency key, so override this overload to honour one.

IDurableFuture<TResponse> CallFuture<TResponse>(string service, string handler, object? request, CallOptions options)

Parameters

service string
handler string
request object
options CallOptions

Returns

IDurableFuture<TResponse>

Type Parameters

TResponse

CallFuture<TResponse>(string, string, string, object?)

Calls a handler on a keyed virtual object or workflow and returns a non-blocking future.

IDurableFuture<TResponse> CallFuture<TResponse>(string service, string key, string handler, object? request = null)

Parameters

service string
key string
handler string
request object

Returns

IDurableFuture<TResponse>

Type Parameters

TResponse

CallFuture<TResponse>(string, string, string, object?, CallOptions)

Calls a handler on a keyed virtual object or workflow with call options and returns a non-blocking future. Defaulted like CallFuture<TResponse>(string, string, object?, CallOptions), with the same limits on the options it honours.

IDurableFuture<TResponse> CallFuture<TResponse>(string service, string key, string handler, object? request, CallOptions options)

Parameters

service string
key string
handler string
request object
options CallOptions

Returns

IDurableFuture<TResponse>

Type Parameters

TResponse

Call<TResponse>(string, string, object?)

Calls a handler on a stateless service and awaits its response.

ValueTask<TResponse> Call<TResponse>(string service, string handler, object? request = null)

Parameters

service string
handler string
request object

Returns

ValueTask<TResponse>

Type Parameters

TResponse

Call<TResponse>(string, string, object?, CallOptions)

Calls a handler on a stateless service with call options (e.g., idempotency key).

ValueTask<TResponse> Call<TResponse>(string service, string handler, object? request, CallOptions options)

Parameters

service string
handler string
request object
options CallOptions

Returns

ValueTask<TResponse>

Type Parameters

TResponse

Call<TResponse>(string, string, string, object?)

Calls a handler on a keyed virtual object or workflow and awaits its response.

ValueTask<TResponse> Call<TResponse>(string service, string key, string handler, object? request = null)

Parameters

service string
key string
handler string
request object

Returns

ValueTask<TResponse>

Type Parameters

TResponse

Call<TResponse>(string, string, string, object?, CallOptions)

Calls a handler on a keyed virtual object or workflow with call options.

ValueTask<TResponse> Call<TResponse>(string service, string key, string handler, object? request, CallOptions options)

Parameters

service string
key string
handler string
request object
options CallOptions

Returns

ValueTask<TResponse>

Type Parameters

TResponse

Call<TRequest, TResponse>(string, string, TRequest, string?)

Calls a handler by service and handler name with typed request/response serialization.

ValueTask<TResponse> Call<TRequest, TResponse>(string service, string handler, TRequest request, string? key = null)

Parameters

service string
handler string
request TRequest
key string

Returns

ValueTask<TResponse>

Type Parameters

TRequest
TResponse

Call<TRequest, TResponse>(string, string, TRequest, string?, CallOptions)

Calls a handler with typed request/response serialization and call options (idempotency key, scope, limit key). Defaulted so that external implementations keep compiling: an idempotency key is forwarded to the untyped options overload, which carries it, while a scope or limit key — which no other overload carries — is reported rather than dropped. Override this overload to serialize the request with its static type while honouring a scope or limit key.

ValueTask<TResponse> Call<TRequest, TResponse>(string service, string handler, TRequest request, string? key, CallOptions options)

Parameters

service string
handler string
request TRequest
key string
options CallOptions

Returns

ValueTask<TResponse>

Type Parameters

TRequest
TResponse

CancelInvocation(string)

Cancels a running invocation by sending a cancel signal. The target invocation will be aborted with a cancellation error.

ValueTask CancelInvocation(string invocationId)

Parameters

invocationId string

Returns

ValueTask

GetOutput<T>(string)

Gets the output of a completed invocation, or default if not yet completed.

ValueTask<T?> GetOutput<T>(string invocationId)

Parameters

invocationId string

Returns

ValueTask<T>

Type Parameters

T

Now()

Returns the current time, durably journaled for replay safety.

ValueTask<DateTimeOffset> Now()

Returns

ValueTask<DateTimeOffset>

RejectAwakeable(string, string)

Rejects a previously created awakeable with a failure reason.

void RejectAwakeable(string id, string reason)

Parameters

id string
reason string

RejectSignal(string, int, string)

Rejects an unnamed signal on another invocation, addressed by its index.

ValueTask RejectSignal(string invocationId, int signalIndex, string reason)

Parameters

invocationId string
signalIndex int
reason string

Returns

ValueTask

RejectSignal(string, string, string)

Rejects a named signal on another invocation.

ValueTask RejectSignal(string invocationId, string name, string reason)

Parameters

invocationId string
name string
reason string

Returns

ValueTask

ResolveAwakeable<T>(string, T, ISerde<T>?)

Resolves a previously created awakeable with a payload.

void ResolveAwakeable<T>(string id, T payload, ISerde<T>? serde = null)

Parameters

id string
payload T
serde ISerde<T>

Type Parameters

T

ResolveSignal<T>(string, int, T)

Resolves an unnamed signal on another invocation, addressed by its index.

ValueTask ResolveSignal<T>(string invocationId, int signalIndex, T value)

Parameters

invocationId string
signalIndex int
value T

Returns

ValueTask

Type Parameters

T

ResolveSignal<T>(string, string, T)

Resolves a named signal on another invocation. Defaulted so that adding it does not break external implementations of this interface (mirroring Logger).

ValueTask ResolveSignal<T>(string invocationId, string name, T value)

Parameters

invocationId string
name string
value T

Returns

ValueTask

Type Parameters

T

Run(string, Func<IRunContext, Task>)

Executes an async void side effect with a restricted run context.

ValueTask Run(string name, Func<IRunContext, Task> action)

Parameters

name string
action Func<IRunContext, Task>

Returns

ValueTask

Run(string, Func<Task>)

Executes an async void side effect durably.

ValueTask Run(string name, Func<Task> action)

Parameters

name string
action Func<Task>

Returns

ValueTask

Run(string, Func<Task>, RetryPolicy)

Executes an async void side effect durably with a custom retry policy.

ValueTask Run(string name, Func<Task> action, RetryPolicy retryPolicy)

Parameters

name string
action Func<Task>
retryPolicy RetryPolicy

Returns

ValueTask

RunAsync<T>(string, Func<Task<T>>)

Executes an async side effect and returns a non-blocking future.

IDurableFuture<T> RunAsync<T>(string name, Func<Task<T>> action)

Parameters

name string
action Func<Task<T>>

Returns

IDurableFuture<T>

Type Parameters

T

Remarks

The result is the object the action returned on the attempt that ran it, and a copy deserialized from the journal on every later attempt, so T must round-trip through the configured serializer and callers must not rely on reference identity.

Run<T>(string, Func<IRunContext, Task<T>>)

Executes an async side effect with a restricted run context. Prevents nested Restate operations.

ValueTask<T> Run<T>(string name, Func<IRunContext, Task<T>> action)

Parameters

name string
action Func<IRunContext, Task<T>>

Returns

ValueTask<T>

Type Parameters

T

Remarks

The result is the object the action returned on the attempt that ran it, and a copy deserialized from the journal on every later attempt, so T must round-trip through the configured serializer and callers must not rely on reference identity.

Run<T>(string, Func<Task<T>>)

Executes an async side effect durably. The result is journaled and replayed on retries.

ValueTask<T> Run<T>(string name, Func<Task<T>> action)

Parameters

name string
action Func<Task<T>>

Returns

ValueTask<T>

Type Parameters

T

Remarks

The result is the object the action returned on the attempt that ran it, and a copy deserialized from the journal on every later attempt, so T must round-trip through the configured serializer and callers must not rely on reference identity.

Run<T>(string, Func<Task<T>>, RetryPolicy)

Executes an async side effect durably with a custom retry policy. The SDK retries locally with exponential backoff before propagating failures.

ValueTask<T> Run<T>(string name, Func<Task<T>> action, RetryPolicy retryPolicy)

Parameters

name string
action Func<Task<T>>
retryPolicy RetryPolicy

Returns

ValueTask<T>

Type Parameters

T

Remarks

The result is the object the action returned on the attempt that ran it, and a copy deserialized from the journal on every later attempt, so T must round-trip through the configured serializer and callers must not rely on reference identity.

Run<T>(string, Func<T>)

Executes a synchronous side effect durably. The result is journaled and replayed on retries.

ValueTask<T> Run<T>(string name, Func<T> action)

Parameters

name string
action Func<T>

Returns

ValueTask<T>

Type Parameters

T

Remarks

The result is the object the action returned on the attempt that ran it, and a copy deserialized from the journal on every later attempt, so T must round-trip through the configured serializer and callers must not rely on reference identity.

Run<T>(string, Func<T>, RetryPolicy)

Executes a synchronous side effect durably with a custom retry policy. The SDK retries locally with exponential backoff before propagating failures.

ValueTask<T> Run<T>(string name, Func<T> action, RetryPolicy retryPolicy)

Parameters

name string
action Func<T>
retryPolicy RetryPolicy

Returns

ValueTask<T>

Type Parameters

T

Remarks

The result is the object the action returned on the attempt that ran it, and a copy deserialized from the journal on every later attempt, so T must round-trip through the configured serializer and callers must not rely on reference identity.

Send(string, string, object?, SendOptions)

Sends a one-way invocation with send options (delay, idempotency key, scope, limit key).

ValueTask<InvocationHandle> Send(string service, string handler, object? request, SendOptions options)

Parameters

service string
handler string
request object
options SendOptions

Returns

ValueTask<InvocationHandle>

Send(string, string, object?, TimeSpan?, string?)

Sends a one-way invocation to a stateless service. Returns a handle to track the invocation.

ValueTask<InvocationHandle> Send(string service, string handler, object? request = null, TimeSpan? delay = null, string? idempotencyKey = null)

Parameters

service string
handler string
request object
delay TimeSpan?
idempotencyKey string

Returns

ValueTask<InvocationHandle>

Send(string, string, string, object?, SendOptions)

Sends a one-way invocation to a keyed virtual object or workflow with send options.

ValueTask<InvocationHandle> Send(string service, string key, string handler, object? request, SendOptions options)

Parameters

service string
key string
handler string
request object
options SendOptions

Returns

ValueTask<InvocationHandle>

Send(string, string, string, object?, TimeSpan?, string?)

Sends a one-way invocation to a keyed virtual object or workflow. Returns a handle to track the invocation.

ValueTask<InvocationHandle> Send(string service, string key, string handler, object? request = null, TimeSpan? delay = null, string? idempotencyKey = null)

Parameters

service string
key string
handler string
request object
delay TimeSpan?
idempotencyKey string

Returns

ValueTask<InvocationHandle>

Send<TRequest>(string, string, TRequest, string?, SendOptions?)

Sends a one-way invocation by service and handler name with typed request serialization.

ValueTask<InvocationHandle> Send<TRequest>(string service, string handler, TRequest request, string? key = null, SendOptions? options = null)

Parameters

service string
handler string
request TRequest
key string
options SendOptions?

Returns

ValueTask<InvocationHandle>

Type Parameters

TRequest

Signal<T>()

Awaits an unnamed signal; the returned SignalHandle<T> carries the index this call allocates, which addresses the signal on this invocation. Defaulted for the same reason as Signal<T>(string).

SignalHandle<T> Signal<T>()

Returns

SignalHandle<T>

Type Parameters

T

Signal<T>(string)

Awaits a signal by name, resolved or rejected by another handler holding this invocation handle. Defaulted so that adding it does not break external implementations of this interface (mirroring Logger).

IDurableFuture<T> Signal<T>(string name)

Parameters

name string

Returns

IDurableFuture<T>

Type Parameters

T

Sleep(TimeSpan)

Suspends execution for the specified duration. Durable — survives process restarts.

ValueTask Sleep(TimeSpan duration)

Parameters

duration TimeSpan

Returns

ValueTask

Timer(TimeSpan)

Creates a non-blocking durable timer that completes after the specified duration.

IDurableFuture Timer(TimeSpan duration)

Parameters

duration TimeSpan

Returns

IDurableFuture