deterministic_select

Macro deterministic_select 

Source
macro_rules! deterministic_select {
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr, if $guard1:expr => $body1:expr,
        $pat2:pat = $fut2:expr, if $guard2:expr => $body2:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr, if $guard1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr, if $guard2:expr => $body2:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr,
        $pat3:pat = $fut3:expr => $body3:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr,
        $pat3:pat = $fut3:expr, if $guard3:expr => $body3:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr, if $guard2:expr => $body2:expr,
        $pat3:pat = $fut3:expr, if $guard3:expr => $body3:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr,
        $pat3:pat = $fut3:expr => $body3:expr,
        $pat4:pat = $fut4:expr => $body4:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr,
        $pat3:pat = $fut3:expr, if $guard3:expr => $body3:expr,
        $pat4:pat = $fut4:expr => $body4:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr => $body2:expr,
        $pat3:pat = $fut3:expr => $body3:expr,
        $pat4:pat = $fut4:expr => $body4:expr,
        $pat5:pat = $fut5:expr => $body5:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr, if $guard2:expr => $body2:expr,
        $pat3:pat = $fut3:expr, if $guard3:expr => $body3:expr,
        $pat4:pat = $fut4:expr => $body4:expr,
        $pat5:pat = $fut5:expr, if $guard5:expr => $body5:expr $(,)?
    ) => { ... };
    (
        $pat1:pat = $fut1:expr => $body1:expr,
        $pat2:pat = $fut2:expr, if $guard2:expr => $body2:expr,
        $pat3:pat = $fut3:expr, if $guard3:expr => $body3:expr,
        $pat4:pat = $fut4:expr => $body4:expr,
        $pat5:pat = $fut5:expr => $body5:expr,
        $pat6:pat = $fut6:expr => $body6:expr,
        $pat7:pat = $fut7:expr => $body7:expr $(,)?
    ) => { ... };
}
Expand description

The deterministic_select! macro waits on multiple async operations simultaneously, returning when one of them completes. Branch ordering is determined by GlobalRng for deterministic but fair selection.

ยงFeatures

  • Supports if guards: pat = fut, if condition => body
  • Supports else branch: runs when all branches are disabled by guards
  • Up to 5 branches are supported