Skip to main content

WorkflowContextKey

Trait WorkflowContextKey 

Source
pub trait WorkflowContextKey: 'static {
    type Value: 'static;
}
Expand description

A typed key for values stored in the current workflow execution context.

Implement this trait on a dedicated marker type shared by the workflow and its interceptors. The marker type itself is the key, so different markers can store the same value type without colliding.

§Scope and propagation

A scope inherits the values active when it is created. A nested scope shadows only its selected key. Plain child futures polled inside a scope see that scope, while separately scoped concurrent futures retain their own snapshots. Independently scheduled signal and update handlers start without another routine’s values; an inbound interceptor or the handler itself can establish a handler-local scope.

Values remain installed only while scoped workflow code is being polled. The SDK restores the prior snapshot on suspension, completion, cancellation by dropping the future, and panic. This prevents a value from leaking to another routine sharing the workflow’s single-threaded executor, or to another workflow execution. Cache eviction drops all values; replay recreates them by executing the same deterministic scope calls.

Storage is in-memory and local to one workflow run. Cross-boundary propagation is explicit: outbound interceptors read values and write headers for activities, local activities, child workflows, signals, Nexus operations, or continue-as-new, and inbound interceptors decode those headers and establish a new scope.

use temporalio_workflow::WorkflowContextKey;

struct RequestId;

impl WorkflowContextKey for RequestId {
    type Value = String;
}

Required Associated Types§

Source

type Value: 'static

Value stored under this key.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§