Table of Contents

Class SharedObjectContext

Namespace
Restate.Sdk
Assembly
Restate.Sdk.dll

Context for shared handlers on virtual objects. Provides read-only state access and can run concurrently with other shared handlers for the same key.

public abstract class SharedObjectContext : Context, ISharedObjectContext, IContext
Inheritance
SharedObjectContext
Implements
Derived
Inherited Members

Properties

Aborted

Cancellation token that fires when the invocation is aborted.

public override CancellationToken Aborted { get; }

Property Value

CancellationToken

Console

Console that is silent during replay to avoid duplicate output.

public override DurableConsole Console { get; }

Property Value

DurableConsole

Headers

Request headers from the original invocation.

public override IReadOnlyDictionary<string, string> Headers { get; }

Property Value

IReadOnlyDictionary<string, string>

InvocationId

Unique identifier of the current invocation.

public override string InvocationId { get; }

Property Value

string

Key

The key of the virtual object instance.

public abstract string Key { 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 for custom test doubles; the SDK-provided contexts override it with a replay-aware logger.

public override ILogger Logger { get; }

Property Value

ILogger

Random

Replay-safe random number generator seeded by the invocation.

public override DurableRandom Random { get; }

Property Value

DurableRandom

Methods

Attach<T>(string)

Attaches to a running invocation and awaits its result.

public override 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.

public override 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. Use with combinators for concurrent fan-out patterns.

public override 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.

public override 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.

public override 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.

public override 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.

public override 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).

public override 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.

public override 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.

public override 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. Use this when you don't have generated typed clients.

public override 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).

public override 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.

public override 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.

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

Parameters

invocationId string

Returns

ValueTask<T>

Type Parameters

T

Get<T>(StateKey<T>)

Gets the value for the given state key, or default if not set.

public abstract ValueTask<T?> Get<T>(StateKey<T> key)

Parameters

key StateKey<T>

Returns

ValueTask<T>

Type Parameters

T

Get<T>(StateKey<T>, string?)

Gets the value for the given state key, or default if not set, labelling the journal entry with entryName so it reads as that name in the Restate UI. The name is observability only: it does not change what is read. The default implementation drops the name and reads through Get<T>(StateKey<T>), so contexts that predate entry names keep working.

public virtual ValueTask<T?> Get<T>(StateKey<T> key, string? entryName)

Parameters

key StateKey<T>
entryName string

Returns

ValueTask<T>

Type Parameters

T

Now()

Returns the current time, durably journaled for replay safety.

public override ValueTask<DateTimeOffset> Now()

Returns

ValueTask<DateTimeOffset>

ObjectClient<TClient>(string)

Gets a source-generated typed call client for a virtual object, bound to the given key.

public override TClient ObjectClient<TClient>(string key) where TClient : class

Parameters

key string

Returns

TClient

Type Parameters

TClient

ObjectSendClient<TClient>(string, SendOptions?)

Gets a source-generated typed send client for a virtual object, bound to the given key.

public override TClient ObjectSendClient<TClient>(string key, SendOptions? options = null) where TClient : class

Parameters

key string
options SendOptions?

Returns

TClient

Type Parameters

TClient

RejectAwakeable(string, string)

Rejects a previously created awakeable with a failure reason.

public override 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.

public override 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: the awaiting handler's future fails with a TerminalException carrying reason.

public override 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.

public override 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 (see Signal<T>()).

public override 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. The awaiting handler receives value from its Signal<T>(string) future.

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

Parameters

invocationId string

The invocation to signal, from an InvocationHandle.

name string

The signal name the target handler awaits.

value T

The value the signal resolves with.

Returns

ValueTask

Type Parameters

T

Run(string, Func<IRunContext, Task>)

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

public override 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.

public override 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.

public override 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. The action runs immediately but the returned future resolves when the server acknowledges the result. Use with All<T>(params ReadOnlySpan<IDurableFuture<T>>) or Race<T>(params ReadOnlySpan<IDurableFuture<T>>) for concurrent task patterns.

public override 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.

public override 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.

public override 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.

public override 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.

public override 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.

public override 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 to a stateless service with send options (delay, idempotency key, scope, limit key).

public override 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.

public override 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.

public override 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.

public override 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. Returns a handle to track the invocation.

public override 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

ServiceClient<TClient>()

Gets a source-generated typed call client for a stateless service.

public override TClient ServiceClient<TClient>() where TClient : class

Returns

TClient

Type Parameters

TClient

ServiceSendClient<TClient>(SendOptions?)

Gets a source-generated typed send client for a stateless service.

public override TClient ServiceSendClient<TClient>(SendOptions? options = null) where TClient : class

Parameters

options SendOptions?

Returns

TClient

Type Parameters

TClient

Signal<T>()

Awaits an unnamed signal, addressed by the index this call allocates: the returned SignalHandle<T> carries that index alongside the future. Indices below the first user index are reserved for built-in signals, and they come from the same allocator Awakeable<T>(ISerde<T>?) uses — an awakeable is an unnamed signal plus the opaque id that addresses it, so use Awakeable<T>(ISerde<T>?) when the resolver needs an id to carry around, and this when the resolver addresses the invocation handle and Index.

public override SignalHandle<T> Signal<T>()

Returns

SignalHandle<T>

Type Parameters

T

Signal<T>(string)

Awaits a signal by name. Another handler holding this invocation handle resolves or rejects the signal by that name, and the returned future composes with All<T>(params ReadOnlySpan<IDurableFuture<T>>), Race<T>(params ReadOnlySpan<IDurableFuture<T>>), Any<T>(params ReadOnlySpan<IDurableFuture<T>>) and AllSettled<T>(params ReadOnlySpan<IDurableFuture<T>>) like any other durable future. A signal resolved before this attempt started resolves from the journal on replay. The ingress addresses signals by awakeable id only, so a named signal has no ingress route — use Awakeable<T>(ISerde<T>?) when an external system must complete it.

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

Parameters

name string

The signal name the resolver addresses. Must not be empty.

Returns

IDurableFuture<T>

Type Parameters

T

Sleep(TimeSpan)

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

public override ValueTask Sleep(TimeSpan duration)

Parameters

duration TimeSpan

Returns

ValueTask

StateKeys()

Lists all state keys for this virtual object instance.

public abstract ValueTask<string[]> StateKeys()

Returns

ValueTask<string[]>

StateKeys(string?)

Lists all state keys for this virtual object instance, labelling the journal entry with entryName. The name is observability only; the default implementation drops it and reads through StateKeys().

public virtual ValueTask<string[]> StateKeys(string? entryName)

Parameters

entryName string

Returns

ValueTask<string[]>

Timer(TimeSpan)

Creates a non-blocking durable timer that completes after the specified duration. Unlike Sleep(TimeSpan) which blocks, this returns a future for use with combinators.

public override IDurableFuture Timer(TimeSpan duration)

Parameters

duration TimeSpan

Returns

IDurableFuture

WorkflowClient<TClient>(string)

Gets a source-generated typed call client for a workflow, bound to the given key.

public override TClient WorkflowClient<TClient>(string key) where TClient : class

Parameters

key string

Returns

TClient

Type Parameters

TClient

WorkflowSendClient<TClient>(string, SendOptions?)

Gets a source-generated typed send client for a workflow, bound to the given key.

public override TClient WorkflowSendClient<TClient>(string key, SendOptions? options = null) where TClient : class

Parameters

key string
options SendOptions?

Returns

TClient

Type Parameters

TClient