Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::fiber< TReturn > Class Template Reference

Fiber class providing a stackfull coroutine. More...

#include <asyncpp/fiber.h>

Public Member Functions

template<typename FN >
requires (!std::is_same_v<FN, fiber>)
 fiber (FN &&function, size_t stack_size=262144)
 Construct a new fiber for the specified entry function.
 
constexpr fiber () noexcept=default
 Construct an empty fiber handle.
 
 fiber (fiber &&other) noexcept
 Move constructor. The moved from handle will be empty.
 
fiberoperator= (fiber &&other) noexcept
 Move constructor. The moved from handle will be empty.
 
 fiber (const fiber &)=delete
 
fiberoperator= (const fiber &)=delete
 
auto await () &
 Get an awaitable for this fiber.
 
auto await () &&
 Get an awaitable for this fiber.
 
auto operator co_await () &
 Get an awaitable for this fiber.
 
auto operator co_await () &&
 Get an awaitable for this fiber.
 

Static Public Member Functions

template<typename T >
static auto fiber_await (T &&awaiter)
 Await a standard C++20 coroutine awaitable.
 

Detailed Description

template<typename TReturn>
class asyncpp::fiber< TReturn >

Fiber class providing a stackfull coroutine.

Constructor & Destructor Documentation

◆ fiber()

template<typename TReturn >
template<typename FN >
requires (!std::is_same_v<FN, fiber>)
asyncpp::fiber< TReturn >::fiber ( FN && function,
size_t stack_size = 262144 )
inlineexplicit

Construct a new fiber for the specified entry function.

The specified function gets placed as the first function in the backtrace of the fiber and is invoked on its own stack once the fiber is awaited. Once the entry function returns a coroutine awaiting the fiber will resume. You can freely specify the stack size and it will get rounded to the next possible value after adding all overhead (guard pages). Keep in mind that most platforms treat exceeding the stack space like a segmentation fault and will terminate your program. This stack_size is a final amount, unlike the normal thread stack it does not grow automatically.

Parameters
functionThe function to execute when the fiber is started.
stack_sizeThe requested stack size in bytes. This value is rounded up to the next page size.
Template Parameters
FN

Member Function Documentation

◆ await() [1/2]

template<typename TReturn >
auto asyncpp::fiber< TReturn >::await ( ) &
inline

Get an awaitable for this fiber.

Returns
auto An awaiter that is resumed once the fiber finishes

◆ await() [2/2]

template<typename TReturn >
auto asyncpp::fiber< TReturn >::await ( ) &&
inline

Get an awaitable for this fiber.

Returns
auto An awaiter that is resumed once the fiber finishes

◆ fiber_await()

template<typename TReturn >
template<typename T >
static auto asyncpp::fiber< TReturn >::fiber_await ( T && awaiter)
inlinestatic

Await a standard C++20 coroutine awaitable.

Pauses the fiber till the awaited coroutine is done and returns the value generated by it.

Parameters
awaiterThe awaitable to await
Returns
The value generated by the awaitable

◆ operator co_await() [1/2]

template<typename TReturn >
auto asyncpp::fiber< TReturn >::operator co_await ( ) &
inline

Get an awaitable for this fiber.

Returns
auto An awaiter that is resumed once the fiber finishes

◆ operator co_await() [2/2]

template<typename TReturn >
auto asyncpp::fiber< TReturn >::operator co_await ( ) &&
inline

Get an awaitable for this fiber.

Returns
auto An awaiter that is resumed once the fiber finishes

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