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

Fiber class providing a stackfull coroutine with a void return value. 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
 Construct an empty fiber handle.
 
 ~fiber ()
 Destructor.
 
 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 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

Fiber class providing a stackfull coroutine with a void return value.

Constructor & Destructor Documentation

◆ fiber()

template<typename FN >
requires (!std::is_same_v<FN, fiber>)
asyncpp::fiber< void >::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()

auto asyncpp::fiber< void >::await ( )
inline

Get an awaitable for this fiber.

Returns
auto An awaiter that is resumed once the fiber finishes

◆ fiber_await()

template<typename T >
static auto asyncpp::fiber< void >::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()

auto asyncpp::fiber< void >::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: