Skip to main content

all

Macro all 

Source
macro_rules! all {
    ($ctx:expr, $($fut:expr),+ $(,)?) => { ... };
}
Expand description

Waits for all futures to complete successfully.

This macro boxes each future to enable combining heterogeneous future types, then delegates to ctx.all(). All futures run concurrently, and the macro returns when all have completed successfully or when the first error occurs.

§Arguments

  • $ctx - The DurableContext instance
  • $fut - One or more future expressions (comma-separated)

§Returns

  • Ok(Vec<T>) - All results in the same order as the input futures
  • Err(DurableError) - The first error encountered (remaining futures are cancelled)

§Examples

§Basic Usage

use durable_execution_sdk::all;

// Clone contexts for each future to satisfy lifetime requirements
let ctx1 = ctx.clone();
let ctx2 = ctx.clone();
let ctx3 = ctx.clone();

let results = all!(ctx,
    async move { ctx1.step(|_| Ok(1), None).await },
    async move { ctx2.step(|_| Ok(2), None).await },
    async move { ctx3.step(|_| Ok(3), None).await },
).await?;
assert_eq!(results, vec![1, 2, 3]);

§Parallel Data Fetching

use durable_execution_sdk::all;

// Clone contexts for parallel operations
let ctx1 = ctx.clone();
let ctx2 = ctx.clone();
let ctx3 = ctx.clone();

// Fetch multiple pieces of data in parallel
let results = all!(ctx,
    async move { ctx1.step(|_| fetch_user(user_id), None).await },
    async move { ctx2.step(|_| fetch_preferences(user_id), None).await },
    async move { ctx3.step(|_| fetch_notifications(user_id), None).await },
).await?;
let (user, preferences, notifications) = (
    results[0].clone(),
    results[1].clone(),
    results[2].clone()
);

§Error Handling

use durable_execution_sdk::all;

let ctx1 = ctx.clone();
let ctx2 = ctx.clone();
let ctx3 = ctx.clone();

// If any step fails, the entire operation fails
let result = all!(ctx,
    async move { ctx1.step(|_| Ok(1), None).await },
    async move { ctx2.step(|_| Err::<i32, _>("failed".into()), None).await },
    async move { ctx3.step(|_| Ok(3), None).await },  // This may not execute
).await;

assert!(result.is_err());

§When to Use

Use all! when you need all operations to succeed and want to fail fast on the first error. For collecting all outcomes (including failures), use all_settled! instead.

§See Also

  • any! - Return first success
  • race! - Return first to settle
  • all_settled! - Collect all outcomes