D++ (DPP)
C++ Discord API Bot Library
dpp::coroutine Class Reference

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

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...
 
bool await_ready () const
 First function called by the standard library when the coroutine is co_await-ed. More...
 
auto & operator co_await () &noexcept
 Suspend the caller until the coroutine completes. More...
 
const auto & operator co_await () const &noexcept
 Suspend the caller until the coroutine completes. More...
 
auto && operator co_await () &&noexcept
 Suspend the caller until the coroutine completes. More...
 

Friends

class detail::coroutine::coroutine_base< R >
 Internal use only base class containing common logic between coroutine<R> and coroutine<void>. It also serves to prevent await_suspend and await_resume from being used directly. More...
 

Detailed Description

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

The type of the result produced by this coroutine.

Constructor & Destructor Documentation

◆ coroutine() [1/3]

dpp::coroutine::coroutine ( )
default

Default constructor, creates an empty coroutine.

◆ coroutine() [2/3]

dpp::coroutine::coroutine ( const coroutine )
delete

Copy constructor is disabled.

◆ coroutine() [3/3]

dpp::coroutine::coroutine ( coroutine &&  other)
noexcept

Move constructor, grabs another coroutine's handle.

Parameters
otherCoroutine to move the handle from

◆ ~coroutine()

dpp::coroutine::~coroutine ( )

Destructor, destroys the handle.

Member Function Documentation

◆ await_ready()

bool dpp::coroutine::await_ready ( ) const

First function called by the standard library when the coroutine is co_await-ed.

Remarks
Do not call this manually, use the co_await keyword instead.
Exceptions
invalid_operation_exceptionif the coroutine is empty or finished.
Returns
bool Whether the coroutine is done

◆ operator co_await() [1/3]

auto&& dpp::coroutine::operator co_await ( ) &&
inlinenoexcept

Suspend the caller until the coroutine completes.

Exceptions
Onresumption, any exception thrown by the coroutine is propagated to the caller.
Returns
On resumption, this expression evaluates to the result object of type R, as an rvalue reference.

◆ operator co_await() [2/3]

auto& dpp::coroutine::operator co_await ( ) &
inlinenoexcept

Suspend the caller until the coroutine completes.

Exceptions
Onresumption, any exception thrown by the coroutine is propagated to the caller.
Returns
On resumption, this expression evaluates to the result object of type R, as a reference.

◆ operator co_await() [3/3]

const auto& dpp::coroutine::operator co_await ( ) const &
inlinenoexcept

Suspend the caller until the coroutine completes.

Exceptions
Onresumption, any exception thrown by the coroutine is propagated to the caller.
Returns
On resumption, this expression evaluates to the result object of type R, as a const reference.

◆ operator=() [1/2]

coroutine& dpp::coroutine::operator= ( const coroutine )
delete

Copy assignment is disabled.

◆ operator=() [2/2]

coroutine& dpp::coroutine::operator= ( coroutine &&  other)
noexcept

Move assignment, grabs another coroutine's handle.

Parameters
otherCoroutine to move the handle from

Friends And Related Function Documentation

◆ detail::coroutine::coroutine_base< R >

friend class detail::coroutine::coroutine_base< R >
friend

Internal use only base class containing common logic between coroutine<R> and coroutine<void>. It also serves to prevent await_suspend and await_resume from being used directly.

Warning
For internal use only, do not use.
See also
operator co_await()
D++ 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