Fiber class providing a stackfull coroutine.
More...
#include <asyncpp/fiber.h>
|
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.
|
|
fiber & | operator= (fiber &&other) noexcept |
| Move constructor. The moved from handle will be empty.
|
|
| fiber (const fiber &)=delete |
|
fiber & | operator= (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.
|
|
|
template<typename T > |
static auto | fiber_await (T &&awaiter) |
| Await a standard C++20 coroutine awaitable.
|
|
template<typename TReturn>
class asyncpp::fiber< TReturn >
Fiber class providing a stackfull coroutine.
◆ 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
-
function | The function to execute when the fiber is started. |
stack_size | The requested stack size in bytes. This value is rounded up to the next page size. |
- Template Parameters
-
◆ await() [1/2]
template<typename TReturn >
Get an awaitable for this fiber.
- Returns
- auto An awaiter that is resumed once the fiber finishes
◆ await() [2/2]
template<typename TReturn >
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 >
Await a standard C++20 coroutine awaitable.
Pauses the fiber till the awaited coroutine is done and returns the value generated by it.
- Parameters
-
awaiter | The awaitable to await |
- Returns
- The value generated by the awaitable
◆ operator co_await() [1/2]
template<typename TReturn >
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 >
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: