pub trait ContextSignals<'ctx>: SealedContext<'ctx> {
// Provided method
fn signal<T: Deserialize + 'static>(
&self,
name: &str,
) -> impl DurableFuture<Output = Result<T, TerminalError>> + Send + 'ctx { ... }
}Expand description
§Signals
Signals let invocations communicate with each other. A signal is a named, one-shot durable promise scoped to a specific invocation: a running handler awaits a signal by name, and any other handler completes it by targeting the awaiter’s invocation id and the same signal name.
Signals are similar to awakeables, but instead of an
opaque generated identifier you exfiltrate, they are addressed by (invocation_id, name).
The awaiting handler just needs to share its own invocation id (available via
Context::invocation_id).
§Awaiting a signal
// Wait for a named signal on the current invocation
let value = ctx.signal::<String>("my-signal").await?;The returned future is a DurableFuture, so it can be combined with other durable futures
using crate::select.
§Completing a signal
Another handler completes the signal on the target invocation using its
InvocationHandle:
// Resolve the signal with a value
ctx.invocation_handle(invocation_id)
.signal("my-signal")
.resolve("hello".to_string());
// Or reject it, so the awaiting handler observes a terminal error
ctx.invocation_handle(invocation_id)
.signal("my-signal")
.reject(TerminalError::new("my error reason"));For more info about serialization of the payload, see crate::serde.
Be aware: Virtual Objects only process a single invocation at a time, so the Virtual Object will be blocked while waiting on the signal to be completed.
Provided Methods§
Sourcefn signal<T: Deserialize + 'static>(
&self,
name: &str,
) -> impl DurableFuture<Output = Result<T, TerminalError>> + Send + 'ctx
fn signal<T: Deserialize + 'static>( &self, name: &str, ) -> impl DurableFuture<Output = Result<T, TerminalError>> + Send + 'ctx
Wait for a named signal to arrive on the current invocation.
Signals are identified by name and are scoped to the current invocation. Another handler
can complete this signal via InvocationHandle::signal,
specifying this invocation’s id (available via Context::invocation_id) and the same name.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".