Skip to main content

hedge

Macro hedge 

Source
macro_rules! hedge {
    ($config:expr, $primary:expr, $backup:expr) => { ... };
}
Expand description

Macro for hedging an operation.

In this implementation, this races the primary against a timer, and spawns the backup if the timer expires.

§Example

let result = hedge!(
    HedgeConfig::from_millis(100), // hedge delay
    call_primary_server(),         // primary future
    || call_backup_server()        // backup closure (only called if needed)
).await;