Skip to main content

handler

Function handler 

Source
pub fn handler<F, Fut>(f: F) -> DurableHandlerBuilder<F, Fut>
where F: Fn(Value, BuilderContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, DurableError>> + Send,
Expand description

Create a new DurableHandlerBuilder from a handler function.

This is the entry point for the builder-pattern API. The returned builder can be configured and then executed with .run().

§Arguments

  • f — An async function taking the user event and a BuilderContext, returning Result<serde_json::Value, DurableError>

§Examples

use durable_lambda_builder::prelude::*;

#[tokio::main]
async fn main() -> Result<(), lambda_runtime::Error> {
    durable_lambda_builder::handler(|event: serde_json::Value, mut ctx: BuilderContext| async move {
        let result: Result<i32, String> = ctx.step("validate", || async { Ok(42) }).await?;
        Ok(serde_json::json!({"result": result.unwrap()}))
    })
    .run()
    .await
}