D++ (DPP)
C++ Discord API Bot Library
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 >:
+ Collaboration diagram for dpp::coroutine< R >:

Public Types

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

Public Member Functions

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

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

Friends

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

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
RReturn 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)
inlinenoexcept

Move constructor, grabs another coroutine's handle.

Parameters
otherCoroutine 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

◆ 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)
inlinenoexcept

Move assignment, grabs another coroutine's handle.

Parameters
otherCoroutine to move the handle from

◆ sync_wait()

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

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)
inlineinherited

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
durationMaximum 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)
inlineprotectedinherited

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

Template Parameters
TimedWhether the wait function times out or not
Parameters
do_waitFunction 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)
inlineinherited

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
timeMaximum 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 Function 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 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0