Skip to main content

run_durable_handler

Function run_durable_handler 

Source
pub async fn run_durable_handler<E, R, Fut, F>(
    lambda_event: LambdaEvent<DurableExecutionInvocationInput>,
    handler: F,
) -> Result<DurableExecutionInvocationOutput, Error>
where E: DeserializeOwned, R: Serialize, Fut: Future<Output = Result<R, DurableError>>, F: FnOnce(E, DurableContext) -> Fut,
Expand description

Runs a durable execution handler within the Lambda runtime.

This is the core runtime function that the #[durable_execution] macro delegates to. It handles the full lifecycle:

  1. Extract the user’s event from the Lambda input
  2. Set up ExecutionState, checkpoint batcher, and DurableContext
  3. Call the user’s handler
  4. Process the result (serialize, checkpoint large results, map errors)
  5. Clean up (drain batcher, drop state)

§Type Parameters

  • E: The user’s event type (must implement DeserializeOwned)
  • R: The user’s result type (must implement Serialize)
  • Fut: The future returned by the handler
  • F: The handler function

§Example

use durable_execution_sdk::runtime::run_durable_handler;

// Called automatically by #[durable_execution], but can be used directly:
pub async fn my_handler(
    event: LambdaEvent<DurableExecutionInvocationInput>,
) -> Result<DurableExecutionInvocationOutput, lambda_runtime::Error> {
    run_durable_handler(event, |event: MyEvent, ctx| async move {
        let result = ctx.step(|_| Ok(42), None).await?;
        Ok(MyResult { value: result })
    }).await
}