wwa-coro 0.0.1
Yet Another C++20 Coroutine Library
eager_task.h File Reference

Eager coroutine. More...

#include <coroutine>
#include <exception>
#include <functional>
+ Include dependency graph for eager_task.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  wwa::coro::eager_task
 Eager coroutine. More...
 
struct  wwa::coro::eager_task::promise_type
 The promise type for the eager_task coroutine. More...
 

Namespaces

namespace  wwa
 
namespace  wwa::coro
 Library namespace.
 

Functions

template<typename Awaitable, typename... Args>
eager_task wwa::coro::run_awaitable (Awaitable &&f, Args &&... args)
 Turns any awaitable into an eager fire-and-forget coroutine.
 

Detailed Description

Eager coroutine.

This header file defines the eager_task class, which represents an eager coroutine that starts execution immediately upon creation. It also includes the run_awaitable function template, which turns any awaitable into an eager fire-and-forget coroutine.

// Sample awaitable
{
co_return 3;
}
wwa::coro::eager_task my_eager_task()
{
const auto result = co_await my_task(); // Can be any awaitable
std::cout << "Result: " << result << "\n";
}
std::cout << "Starting eager task..." << "\n";
my_eager_task();
std::cout << "Eager task finished." << "\n";

Definition in file eager_task.h.