Skip to main content

select

Macro select 

Source
macro_rules! select {
    (biased; $($branches:tt)*) => { ... };
    (else => $($rest:tt)*) => { ... };
    ($p:pat = $($t:tt)*) => { ... };
    () => { ... };
}
Expand description

Waits on multiple concurrent branches, returning when the first completes, with a deterministic, seed-controlled polling order.

Drop-in replacement for tokio::select! with the same grammar:

select! {
    <pattern> = <async expression> (, if <precondition>)? => <handler>,
    ...
    (else => <handler>)?
}

By default the branch polled first is chosen, on every poll, by an offset drawn from select_support::select_offset: inside a moonpool simulation that source is seeded (same seed, same choices, exact replay; different seeds explore different orderings), and outside a simulation it is entropy-based, matching tokio’s production behavior.

select! { biased; ... } skips the draw entirely and forwards verbatim to tokio::select! { biased; ... }: branches are polled top to bottom, which is already fully deterministic. Use it when branches have a natural priority (shutdown or timeout guards); use the default form when branches are peers racing for the same wake (message queues, notify channels), so the simulation can explore both winners across seeds.

§Examples

let winner = moonpool_core::select! {
    x = async { 1 } => x,
    _ = std::future::pending::<()>() => unreachable!(),
};
assert_eq!(winner, 1);

See the module docs for the full walkthrough of how the offset is injected into tokio’s own expansion.