boost::capy::when_any

when_any overloads

Synopses

Declared in <boost/capy/when_any.hpp>

Race results‐returning awaitables, selecting the first success.

template<ContextAwaitable... As>
requires (sizeof...(As) > 0)
          && detail::all_results_awaitables<As...>
[[nodiscard]]
task<std::variant<std::error_code, /* implementation-defined */...>>
when_any(As... as);

Race a range of results‐returning awaitables (non‐void payloads).

template<ContextAwaitableRange R>
requires detail::is_results_v<
        awaitable_result_t<std::ranges::range_value_t<R>>>
    && (!std::is_same_v<
            detail::results_payload_t<
                awaitable_result_t<std::ranges::range_value_t<R>>>,
            std::tuple<>>)
[[nodiscard]]
task<std::variant<std::error_code, std::pair<std::size_t, /* implementation-defined */>>>
when_any(R&& awaitables);

Race a range of void results‐returning awaitables.

template<ContextAwaitableRange R>
requires detail::is_results_v<
        awaitable_result_t<std::ranges::range_value_t<R>>>
    && std::is_same_v<
            detail::results_payload_t<
                awaitable_result_t<std::ranges::range_value_t<R>>>,
            std::tuple<>>
[[nodiscard]]
task<std::variant<std::error_code, std::size_t>>
when_any(R&& awaitables);

Exceptions

Name

Thrown on

std::invalid_argument

if range is empty.

Return Value

  • A task yielding variant<error_code, R1, ..., Rn> where index 0 is the failure/no‐winner case and index i+1 identifies the winning child. On all‐fail, index 0 holds an error_code from one of the failed children (unspecified which; no priority between errors and exceptions).

  • A task yielding variant<error_code, pair<size_t, PayloadT>> where index 0 is failure and index 1 carries the winner's index and payload.

  • A task yielding variant<error_code, size_t> where index 0 is failure and index 1 carries the winner's index.

The return value should not be discarded.

Parameters

Name

Description

as

The awaitables to race. Each must satisfy ContextAwaitable and is consumed (moved‐from) when when_any is awaited.

awaitables

Range of results‐returning awaitables (must not be empty).

See Also