Example of using an asynchronous generator.
#include <iostream>
namespace {
{
co_return n + 1;
}
{
int v = 0;
while (v < n) {
co_yield v;
v = co_await get_next_value(v);
}
}
{
auto gen = async_first_n(5);
auto it = co_await gen.begin();
auto end = gen.end();
while (it != end) {
std::cout << *it << "\n";
co_await ++it;
}
}
}
int main()
{
async_generator_example();
return 0;
}
An asynchronous generator that produces values of type Result.