dpp::when_any
coro/when_any.h
dpp::when_any::awaiter
dpp::when_any::result
dpp::when_any::state_t
typename... Args Args
size_t N N
std::variant_alternative_t< N+1, variant_type > using dpp::when_any< Args >::result_t = std::variant_alternative_t<N + 1, variant_type> result_t dpp::when_any::result_t

Alias for the result type of the Nth arg.

N

index of the argument to fetch

std::variant< std::exception_ptr, std::remove_cvref_t< detail::when_any::storage_type< detail::awaitable_result< Args > > >... > using dpp::when_any< Args >::variant_type = std::variant<std::exception_ptr, std::remove_cvref_t<detail::when_any::storage_type<detail::awaitable_result<Args>>>...> variant_type dpp::when_any::variant_type

Alias for the type of the result variant.

std::shared_ptr< state_t > std::shared_ptr<state_t> dpp::when_any< Args >::my_state my_state dpp::when_any::my_state {nullptr}

Shared pointer to the state shared between the jobs spawned. Contains the awaitable objects and the result.

size_t N N
job static job dpp::when_any< Args >::make_job (std::shared_ptr< state_t > shared_state) make_job dpp::when_any::make_job std::shared_ptr< state_t > shared_state

Spawn a dpp::job handling the Nth argument.

N

Index of the argument to handle

dpp::job Job handling the Nth argument

Any exceptions from the awaitable's await_suspend should be thrown to the caller (the coroutine creating the when_any object) If the co_await passes, and it is the first one to complete, try construct the result, catch any exceptions to rethrow at resumption, and resume.

void void dpp::when_any< Args >::make_jobs () make_jobs dpp::when_any::make_jobs

Spawn a dpp::job to handle each awaitable. Each of them will co_await the awaitable and set the result if they are the first to finish.

dpp::when_any< Args >::when_any
()=default
when_any
dpp::when_any::when_any

Default constructor. A when_any object created this way holds no state.

typename... Args_ Args_
dpp::when_any< Args >::when_any
(Args_ &&... args)
when_any
dpp::when_any::when_any
Args_ &&... args

Constructor from awaitable objects. Each awaitable is executed immediately and the when_any object can then be co_await-ed later.

???

Any exception thrown by the start of each awaitable will propagate to the caller.

args

Arguments to construct each awaitable from. The when_any object will construct an awaitable for each, it is recommended to pass rvalues or std::move.

dpp::when_any< Args >::when_any
(const when_any &)=delete
when_any
dpp::when_any::when_any
const when_any &

This object is not copyable.

dpp::when_any< Args >::when_any
(when_any &&) noexcept=default
when_any
dpp::when_any::when_any
when_any &&

Move constructor.

dpp::when_any< Args >::~when_any
()
~when_any
dpp::when_any::~when_any

On destruction the when_any will try to call dpp::task::cancel() cancel() on each of its awaitable if they have such a method.

If you are looking to use a custom type with when_any and want it to cancel on its destruction, make sure it has a cancel() method, which will trigger an await_resume() throwing a dpp::task_cancelled_exception. This object will swallow the exception and return cleanly. Any other exception will be thrown back to the resumer.

bool bool dpp::when_any< Args >::await_ready () const noexcept await_ready dpp::when_any::await_ready

Check whether a call to co_await would suspend.

This can change from false to true at any point, but not the other way around.

bool Whether co_await would suspend

awaiter awaiter dpp::when_any< Args >::operator co_await () noexcept operator co_await dpp::when_any::operator co_await

Suspend the caller until any of the awaitables completes.

result

???

On resumption, throws any exception caused by the construction of the result.

result On resumption, this object returns an object that allows to retrieve the index and result of the awaitable.

when_any & when_any & dpp::when_any< Args >::operator= (const when_any &)=delete operator= dpp::when_any::operator= const when_any &

This object is not copyable.

when_any & when_any & dpp::when_any< Args >::operator= (when_any &&) noexcept=default operator= dpp::when_any::operator= when_any &&

Move assignment operator.

Experimental class to co_await on a bunch of awaitable objects, resuming when the first one completes. On completion, returns a result object that contains the index of the awaitable that finished first. A user can call result::index() and result::get<N>() on the result object to get the result, similar to std::variant.

when_any::result

Args...

Type of each awaitable to await on

- dpp::when_any
  await_ready
- dpp::when_any
  make_job
- dpp::when_any
  make_jobs
- dpp::when_any
  my_state
- dpp::when_any
  operator co_await
- dpp::when_any
  operator=
- dpp::when_any
  operator=
- dpp::when_any
  result_t
- dpp::when_any
  variant_type
- dpp::when_any
  when_any
- dpp::when_any
  when_any
- dpp::when_any
  when_any
- dpp::when_any
  when_any
- dpp::when_any
  ~when_any