fiber
Loading...
Searching...
No Matches
fiber::_TryAwait< T, is_rvalue_reference > Class Template Reference

Awaits on something that returns an std::optional and throws if it does not have a value. More...

#include <TryAwait.hpp>

Public Member Functions

 _TryAwait (fiber::Future< T > &&awaitable)
 Hijacks the other awaitable or Future.
 
bool await_ready () const noexcept
 Forwards the ready call to the real awaitable.
 
await_resume ()
 Unpacks the std::optional from the true awaitables await_resume
 
template<class ReturnType>
void await_suspend (std::coroutine_handle< fiber::CoroutinePromise< ReturnType > > handle) noexcept
 Forwards the suspend call to the real awaitable.
 

Detailed Description

template<class T, bool is_rvalue_reference = true>
class fiber::_TryAwait< T, is_rvalue_reference >

Awaits on something that returns an std::optional and throws if it does not have a value.

Example:

Future<int> async_func(); // returns `std::optional<int>` in `co_await`
// TryAwait unpacks the int and throws if the optional does not hold a value
int result = co_await TryAwait(async_func());
}
Owning handle to a coroutine with a custom promise type.
Definition Coroutine.hpp:135
Future and Promise pairs are used to synchronise values between asynchronous tasks.
Definition Future.hpp:62
_TryAwait< T, true > TryAwait(fiber::Future< T > &&future)
Wraps an awaitable that returns an std::optional conditionally unpacks it or throws if there is no va...
Definition TryAwait.hpp:144
int main()
Definition test_main.cpp:23

Constructor & Destructor Documentation

◆ _TryAwait()

template<class T, bool is_rvalue_reference = true>
fiber::_TryAwait< T, is_rvalue_reference >::_TryAwait ( fiber::Future< T > && awaitable)
inline

Hijacks the other awaitable or Future.

Member Function Documentation

◆ await_ready()

template<class T, bool is_rvalue_reference = true>
bool fiber::_TryAwait< T, is_rvalue_reference >::await_ready ( ) const
inlinenoexcept

Forwards the ready call to the real awaitable.

◆ await_resume()

template<class T, bool is_rvalue_reference = true>
T fiber::_TryAwait< T, is_rvalue_reference >::await_resume ( )
inline

Unpacks the std::optional from the true awaitables await_resume

Either returns the the unpacked value of the true awaitables await_resume or throws an fiber::Exception if that optional does not contain a value.

Exceptions
`fiber::Exception`if the awaitables result of type std::otional does not have a value.
Returns
the unpacked value fot the std::optional from the real awaitables await_resume

◆ await_suspend()

template<class T, bool is_rvalue_reference = true>
template<class ReturnType>
void fiber::_TryAwait< T, is_rvalue_reference >::await_suspend ( std::coroutine_handle< fiber::CoroutinePromise< ReturnType > > handle)
inlinenoexcept

Forwards the suspend call to the real awaitable.


The documentation for this class was generated from the following file: