Guides

Sending Events & Signals


Workflow-to-Workflow Signals

Workflows coordinate by forwarding events to other workflows. In Python, a workflow can send an event to a child via child_handle.send_event() (Rust exposes the same on its child handle). In all languages, external systems and API handlers send events through the client-side workflow handle's send_event() / sendEvent(). This enables coordination patterns where a parent workflow controls child execution, or sibling workflows notify each other of progress.

Note: In the TypeScript SDK, child-handle event forwarding (childHandle.sendEvent(...)) is not yet implemented. Forward events to children via the client handle instead, or use Rust/Python for in-workflow child signaling.

1
use orcher::prelude::*;
2
use anyhow::Result;
3
use std::time::Duration;
4
5
#[task]
6
pub async fn expedited_fulfillment(_ctx: TaskContext, order_id: String) -> Result<()> { /* ... */ }
7
8
#[task]
9
pub async fn standard_fulfillment(_ctx: TaskContext, order_id: String) -> Result<()> { /* ... */ }
10
11
// Child workflow that can be expedited via event
12
#[workflow]
13
pub async fn fulfillment_workflow(
14
ctx: WorkflowContext,
15
order_id: String,
16
) -> Result<FulfillmentResult> {
17
// Check for expedite event (5 minute window)
18
let expedite: Option<bool> = ctx
19
.wait_for_event_with_timeout("expedite", Duration::from_secs(300))
20
.await?;
21
22
if expedite.unwrap_or(false) {
23
ctx.execute_task(expedited_fulfillment, order_id).await?;
24
} else {
25
ctx.execute_task(standard_fulfillment, order_id).await?;
26
}
27
28
Ok(FulfillmentResult { completed: true })
29
}
30
31
// Parent workflow that controls the child
32
#[workflow]
33
pub async fn parent_workflow(
34
ctx: WorkflowContext,
35
order_id: String,
36
) -> Result<ParentResult> {
37
// Start child workflow
38
let child_handle = ctx
39
.start_child_workflow("fulfillment_workflow", order_id.clone())
40
.await?;
41
42
// Wait for an external expedite request (1 minute window)
43
let expedite: Option<bool> = ctx
44
.wait_for_event_with_timeout("expedite_request", Duration::from_secs(60))
45
.await?;
46
47
if expedite.unwrap_or(false) {
48
// Forward the expedite signal to the child workflow
49
child_handle.send_event("expedite", true).await?;
50
}
51
52
// Wait for child to complete
53
let result = child_handle.result::<FulfillmentResult>().await?;
54
55
Ok(ParentResult {
56
order_id,
57
expedited: expedite.unwrap_or(false),
58
child_completed: result.completed,
59
})
60
}

Event Buffering

Events are automatically buffered if they arrive before the workflow calls wait_for_event(). This means the order of "send" and "wait" doesn't matter — the event is never lost. On replay, buffered events are replayed from the journal.

Scenario 1 · event arrives before wait
T0 · client sends "approve" → buffered in journal
T1 · workflow calls wait_for_event() → returns immediately from buffer
Scenario 2 · event arrives after wait
T0 · workflow calls wait_for_event() → suspends, claim released
T1 · client sends "approve" → workflow re-queued, resumes
Scenario 3 · multiple events of the same name
T0 · client sends event #1 → buffered
T1 · client sends event #2 → buffered
T2 · wait_for_event() → returns event #1
T3 · wait_for_event() again → returns event #2

Next Steps