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

Search
Loading...
Searching...
No Matches
dpp::coroutine< R > Class Template Reference

Base type for a coroutine, starts on co_await. More...

`#include <coro/coroutine.h>`

Inheritance diagram for dpp::coroutine< R >:
[legend]
Collaboration diagram for dpp::coroutine< R >:
[legend]

## Public Types

using | result_type = R
| The type of the result produced by this coroutine.

## Public Member Functions

| coroutine ()=default
| Default constructor, creates an empty coroutine.
| coroutine (const coroutine &)=delete
| Copy constructor is disabled.
| coroutine (coroutine &&other) noexcept
| Move constructor, grabs another coroutine's handle.
| ~coroutine ()
| Destructor, destroys the handle.
auto | operator co_await ()
coroutine & | operator= (const coroutine &)=delete
| Copy assignment is disabled.
coroutine & | operator= (coroutine &&other) noexcept
| Move assignment, grabs another coroutine's handle.
auto | sync_wait ()
| Blocks this thread and waits for the awaitable to finish.
auto | sync_wait_for (const std::chrono::duration< Rep, Period > &duration)
| Blocks this thread and waits for the awaitable to finish.
auto | sync_wait_until (const std::chrono::time_point< Clock, Duration > &time)
| Blocks this thread and waits for the awaitable to finish.

## Protected Member Functions

auto | sync_wait_impl (auto &&do_wait)
| Implementation for sync_wait. This is code used by sync_wait, sync_wait_for, sync_wait_until.

## Friends

struct | detail::coroutine::promise_t< R >
| Promise has friend access for the constructor.

## Detailed Description

template<typename R>
class dpp::coroutine< R >

Base type for a coroutine, starts on co_await.

Warning
  - This feature is EXPERIMENTAL. The API may change at any time and there may be bugs. Please report any to GitHub Issues or to our Discord Server.
  - Using co_await on this object more than once is undefined behavior.

Template Parameters

  R | Return type of the coroutine. Can be void, or a complete object that supports move construction and move assignment.

## Member Typedef Documentation

## ◆ result_type

template<typename R>

using dpp::coroutine< R >::result_type = R

The type of the result produced by this coroutine.

## Constructor & Destructor Documentation

## ◆ coroutine() [1/3]

template<typename R>

dpp::coroutine< R >::coroutine | ( |  | ) |

default

Default constructor, creates an empty coroutine.

## ◆ coroutine() [2/3]

template<typename R>

dpp::coroutine< R >::coroutine | ( | const coroutine< R > & |  | ) |

delete

Copy constructor is disabled.

## ◆ coroutine() [3/3]

template<typename R>

dpp::coroutine< R >::coroutine | ( | coroutine< R > && | other | ) |

inline noexcept

Move constructor, grabs another coroutine's handle.

Parameters

  other | Coroutine to move the handle from

## ◆ ~coroutine()

template<typename R>

dpp::coroutine< R >::~coroutine | ( |  | ) |

inline

Destructor, destroys the handle.

## Member Function Documentation

## ◆ operator co_await()

template<typename R>

auto dpp::coroutine< R >::operator co_await | ( |  | ) |

inline nodiscard

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

template<typename R>

coroutine & dpp::coroutine< R >::operator= | ( | const coroutine< R > & |  | ) |

delete

Copy assignment is disabled.

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

template<typename R>

coroutine & dpp::coroutine< R >::operator= | ( | coroutine< R > && | other | ) |

inline noexcept

Move assignment, grabs another coroutine's handle.

Parameters

  other | Coroutine to move the handle from

## ◆ sync_wait()

auto dpp::basic_awaitable< coroutine< R > >::sync_wait | ( |  | ) |

inline inherited

Blocks this thread and waits for the awaitable to finish.

Attention
  This will BLOCK THE THREAD. It is likely you want to use co_await instead.

Returns
  If T is void, returns a boolean for which true means the awaitable completed, false means it timed out.
  If T is non-void, returns a std::optional<T> for which an absence of value means timed out.

## ◆ sync_wait_for()

auto dpp::basic_awaitable< coroutine< R > >::sync_wait_for | ( | const std::chrono::duration< Rep, Period > & | duration | ) |

inline inherited

Blocks this thread and waits for the awaitable to finish.

Attention
  This will BLOCK THE THREAD. It is likely you want to use co_await instead.

Parameters

  duration | Maximum duration to wait for

Returns
  If T is void, returns a boolean for which true means the awaitable completed, false means it timed out.
  If T is non-void, returns a std::optional<T> for which an absence of value means timed out.

## ◆ sync_wait_impl()

auto dpp::basic_awaitable< coroutine< R > >::sync_wait_impl | ( | auto && | do_wait | ) |

inline protected inherited

Implementation for sync_wait. This is code used by sync_wait, sync_wait_for, sync_wait_until.

Template Parameters

  Timed | Whether the wait function times out or not

Parameters

  do_wait | Function to do the actual wait on the cv

Returns
  If T is void, returns a boolean for which true means the awaitable completed, false means it timed out.
  If T is non-void, returns a std::optional<T> for which an absence of value means timed out.

## ◆ sync_wait_until()

auto dpp::basic_awaitable< coroutine< R > >::sync_wait_until | ( | const std::chrono::time_point< Clock, Duration > & | time | ) |

inline inherited

Blocks this thread and waits for the awaitable to finish.

Attention
  This will BLOCK THE THREAD. It is likely you want to use co_await instead.

Parameters

  time | Maximum time point to wait for

Returns
  If T is void, returns a boolean for which true means the awaitable completed, false means it timed out.
  If T is non-void, returns a std::optional<T> for which an absence of value means timed out.

## Friends And Related Symbol Documentation

## ◆ detail::coroutine::promise_t< R >

template<typename R>

friend struct detail::coroutine::promise_t< R >

friend

Promise has friend access for the constructor.

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