Does concurrencpp support "co_yield co_await xxx" in generator?
concurrencpp::generator<int> Test::test_generator()
{
int i = 0;
while(i++ < 5)
{
co_yield co_await test_async_task();
}
}
concurrencpp::result<int> Test::test_async_task()
{
co_await runtime.timer_queue()->make_delay_object(std::chrono::milliseconds(5000), runtime.thread_pool_executor());
co_return 42;
}
void Test::onClicked()
{
for (auto value : test_generator())
{
qDebug() << value;
}
}
I think 'co_yield co_await xxx' in generator should work.
Generators are meant to be used synchronously - they can only use the co_yield keyword and must not use the co_await keyword.
what if I don't know how many results there are, such as http streaming responses.
similar to https://github.com/lewissbaker/cppcoro?tab=readme-ov-file#async_generatort
Currently it is not supported, it can be a nice addition to the library. unfortunately there are more important things to implement right now, including asynchronous IO :) I don't see this implemented in the next year, unless someone is willing to implement it and make a PR.