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
Headers
Request headers from the original invocation.
IReadOnlyDictionary<string, string> Headers { get; }
Property Value
InvocationId
Unique identifier of the current invocation.
string InvocationId { get; }
Property Value
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
Methods
Attach<T>(string)
Attaches to a running invocation and awaits its result.
ValueTask<T> Attach<T>(string invocationId)
Parameters
invocationIdstring
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
serdeISerde<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
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
servicestringhandlerstringrequestobjectoptionsCallOptions
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
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
servicestringkeystringhandlerstringrequestobjectoptionsCallOptions
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
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
servicestringhandlerstringrequestobjectoptionsCallOptions
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
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
servicestringkeystringhandlerstringrequestobjectoptionsCallOptions
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
Returns
- ValueTask<TResponse>
Type Parameters
TRequestTResponse
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
servicestringhandlerstringrequestTRequestkeystringoptionsCallOptions
Returns
- ValueTask<TResponse>
Type Parameters
TRequestTResponse
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
invocationIdstring
Returns
GetOutput<T>(string)
Gets the output of a completed invocation, or default if not yet completed.
ValueTask<T?> GetOutput<T>(string invocationId)
Parameters
invocationIdstring
Returns
- ValueTask<T>
Type Parameters
T
Now()
Returns the current time, durably journaled for replay safety.
ValueTask<DateTimeOffset> Now()
Returns
RejectAwakeable(string, string)
Rejects a previously created awakeable with a failure reason.
void RejectAwakeable(string id, string reason)
Parameters
RejectSignal(string, int, string)
Rejects an unnamed signal on another invocation, addressed by its index.
ValueTask RejectSignal(string invocationId, int signalIndex, string reason)
Parameters
Returns
RejectSignal(string, string, string)
Rejects a named signal on another invocation.
ValueTask RejectSignal(string invocationId, string name, string reason)
Parameters
Returns
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
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
Returns
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
Returns
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
namestringactionFunc<IRunContext, Task>
Returns
Run(string, Func<Task>)
Executes an async void side effect durably.
ValueTask Run(string name, Func<Task> action)
Parameters
Returns
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
namestringactionFunc<Task>retryPolicyRetryPolicy
Returns
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
Returns
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
namestringactionFunc<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
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
namestringactionFunc<Task<T>>retryPolicyRetryPolicy
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
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
namestringactionFunc<T>retryPolicyRetryPolicy
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
servicestringhandlerstringrequestobjectoptionsSendOptions
Returns
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
Returns
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
servicestringkeystringhandlerstringrequestobjectoptionsSendOptions
Returns
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
Returns
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
servicestringhandlerstringrequestTRequestkeystringoptionsSendOptions?
Returns
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
namestring
Returns
Type Parameters
T
Sleep(TimeSpan)
Suspends execution for the specified duration. Durable — survives process restarts.
ValueTask Sleep(TimeSpan duration)
Parameters
durationTimeSpan
Returns
Timer(TimeSpan)
Creates a non-blocking durable timer that completes after the specified duration.
IDurableFuture Timer(TimeSpan duration)
Parameters
durationTimeSpan