Skip to main content

CallHandler

Trait CallHandler 

Source
pub trait CallHandler: Send + Sync {
    // Required methods
    fn call_type(&self) -> &str;
    fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        task_name: &'life1 str,
        call_config: &'life2 Value,
        input: &'life3 Value,
        context: &'life4 HandlerContext,
    ) -> Pin<Box<dyn Future<Output = WorkflowResult<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait;
}
Expand description

Handler for call task types that require custom implementations.

Implement this trait to provide support for call types like gRPC, OpenAPI, AsyncAPI, and A2A. Register handlers with WorkflowRunner::with_call_handler().

§Example

use async_trait::async_trait;
use serde_json::Value;
use swf_runtime::{CallHandler, HandlerContext, WorkflowResult};

struct GrpcCallHandler;

#[async_trait]
impl CallHandler for GrpcCallHandler {
    fn call_type(&self) -> &str { "grpc" }

    async fn handle(
        &self,
        task_name: &str,
        call_config: &Value,
        input: &Value,
        context: &HandlerContext,
    ) -> WorkflowResult<Value> {
        // Implement gRPC call logic here
        Ok(serde_json::json!({ "result": "grpc response" }))
    }
}

Required Methods§

Source

fn call_type(&self) -> &str

Returns the call type this handler supports (e.g., “grpc”, “openapi”, “asyncapi”, “a2a”)

Source

fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, task_name: &'life1 str, call_config: &'life2 Value, input: &'life3 Value, context: &'life4 HandlerContext, ) -> Pin<Box<dyn Future<Output = WorkflowResult<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Executes the call with the given configuration, input, and workflow context.

Implementors§