| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::when_any< Args > Class Template Reference

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. More...

`#include <coro/when_any.h>`

## Classes

struct | awaiter
| Object returned by operator co_await(). Meant to be used by the standard library, not by a user. More...
class | result
| Object returned by operator co_await() on resumption. Can be moved but not copied. More...

## Public Member Functions

| when_any ()=default
| Default constructor. A when_any object created this way holds no state.
template<typename... Args_>
| 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.
| when_any (const when_any &)=delete
| This object is not copyable.
| when_any (when_any &&) noexcept=default
| Move constructor.
| ~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.
bool | await_ready () const noexcept
| Check whether a call to co_await would suspend.
awaiter | operator co_await () noexcept
| Suspend the caller until any of the awaitables completes.
when_any & | operator= (const when_any &)=delete
| This object is not copyable.
when_any & | operator= (when_any &&) noexcept=default
| Move assignment operator.

## Detailed Description

template<typename... Args>
class dpp::when_any< Args >

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.

See also
  when_any::result

Template Parameters

  Args... | Type of each awaitable to await on

## Constructor & Destructor Documentation

## ◆ when_any() [1/4]

template<typename... Args>

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

default

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

## ◆ when_any() [2/4]

template<typename... Args>
template<typename... Args_>

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

inline

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

Exceptions

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

Parameters

  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.

## ◆ when_any() [3/4]

template<typename... Args>

dpp::when_any< Args >::when_any | ( | const when_any< Args > & |  | ) |

delete

This object is not copyable.

## ◆ when_any() [4/4]

template<typename... Args>

dpp::when_any< Args >::when_any | ( | when_any< Args > && |  | ) |

default noexcept

Move constructor.

## ◆ ~when_any()

template<typename... Args>

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

inline

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

Note
  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.

## Member Function Documentation

## ◆ await_ready()

template<typename... Args>

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

inline nodiscard noexcept

Check whether a call to co_await would suspend.

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

Returns
  bool Whether co_await would suspend

## ◆ operator co_await()

template<typename... Args>

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

inline nodiscard noexcept

Suspend the caller until any of the awaitables completes.

See also
  result

Exceptions

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

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

## ◆ operator=() [1/2]

template<typename... Args>

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

delete

This object is not copyable.

## ◆ operator=() [2/2]

template<typename... Args>

when_any & dpp::when_any< Args >::operator= | ( | when_any< Args > && |  | ) |

default noexcept

Move assignment operator.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0