Skip to main content

interrupt_with_ctx

Macro interrupt_with_ctx 

Source
macro_rules! interrupt_with_ctx {
    ($ctx:expr, $id:expr, $payload:expr) => { ... };
    ($ctx:expr, $payload:expr) => { ... };
}
Expand description

Interrupt macro for human-in-the-loop interactions (explicit context)

When called, execution either returns a resume value (if resuming) or sends an interrupt signal and returns an error.

This macro requires the context to be passed explicitly. Use the interrupt! macro for the task-local version.

§Syntax

// Anonymous interrupt (auto-generated ID from node name + index):
interrupt_with_ctx!(context, payload)

// Named interrupt (user-specified ID for targeted resume):
interrupt_with_ctx!(context, id, payload)

§Examples

use juncture_core::interrupt;
use serde_json::json;

async fn my_node(state: MyState, ctx: &InterruptContext) -> Result<MyStateUpdate, JunctureError> {
    // Anonymous interrupt -- ID is auto-generated from node + index
    let decision: serde_json::Value = interrupt_with_ctx!(
        ctx,
        json!({"question": "Continue?", "options": ["yes", "no"]})
    )?;

    // Named interrupt -- caller can resume by ID
    let approval: serde_json::Value = interrupt_with_ctx!(
        ctx,
        "approve_step",
        json!({"question": "Approve this action?", "action": "delete"})
    )?;

    Ok(MyStateUpdate::default())
}