Macro select

Source
macro_rules! select {
    (@ {
        // One `_` for each branch in the `select!` macro. Passing this to
        // `count!` converts $skip to an integer.
        ( $($count:tt)* )

        // Normalized select branches. `( $skip )` is a set of `_` characters.
        // There is one `_` for each select branch **before** this one. Given
        // that all input futures are stored in a tuple, $skip is useful for
        // generating a pattern to reference the future for the current branch.
        // $skip is also used as an argument to `count!`, returning the index of
        // the current select branch.
        $( ( $($skip:tt)* ) $bind:pat = $fut:expr => $handle:expr, )+

        // Expression used to special handle cancellation when awaiting select
        ; $on_cancel:expr

        // Fallback expression used when all select branches have been disabled.
        ; $else:expr
    }) => { ... };
    (@ { $($t:tt)* } ) => { ... };
    (@ { $($t:tt)* } on_cancel => $on_cancel:expr $(,)?) => { ... };
    (@ { $($t:tt)* } else => $else:expr $(,)?) => { ... };
    (@ { $($t:tt)* } on_cancel => $on_cancel:expr, else => $else:expr $(,)?) => { ... };
    (@ { $($t:tt)* } else => $else:expr, on_cancel => $on_cancel:expr $(,)?) => { ... };
    (@ { ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:block, $($r:tt)* ) => { ... };
    (@ { ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:expr, $($r:tt)* ) => { ... };
    (@ { ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:block ) => { ... };
    (@ { ( $($s:tt)* ) $($t:tt)* } $p:pat = $f:expr => $h:expr ) => { ... };
    (on_cancel => $on_cancel:expr $(,)? ) => { ... };
    (else => $else:expr $(,)? ) => { ... };
    ( $p:pat = $($t:tt)* ) => { ... };
    () => { ... };
}
Expand description

Select macro, alike tokio::select:

restate_sdk::select! {
    // Bind res to the awakeable result
    res = awakeable => {
        // Handle awakeable result
    },
    _ = ctx.sleep(Duration::from_secs(10)) => {
        // Handle sleep
    },
    // You can also pattern match
    Ok(success_result) = call_result => {
        // Handle success result
    },
    else => {
        // Optional: handle cases when pattern matching doesn't match a future result
        // If unspecified, select panics when there is no match, e.g. in the above select arm,
        // if call_result returns Err, it would panic unless you specify an else arm.
    },
    on_cancel => {
        // Optional: handle when the invocation gets cancelled during this select.
        // If unspecified, it just propagates the TerminalError
    }
}

Note: This API is experimental and subject to changes.