concurrencpp icon indicating copy to clipboard operation
concurrencpp copied to clipboard

Does concurrencpp support "co_yield co_await xxx" in generator?

Open HppZ opened this issue 1 year ago • 5 comments

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;
    }
}

image image

HppZ avatar Apr 19 '24 08:04 HppZ

I think 'co_yield co_await xxx' in generator should work.

HppZ avatar Apr 22 '24 06:04 HppZ

doc

Generators are meant to be used synchronously - they can only use the co_yield keyword and must not use the co_await keyword.

HppZ avatar Apr 22 '24 08:04 HppZ

what if I don't know how many results there are, such as http streaming responses.

HppZ avatar Apr 22 '24 08:04 HppZ

similar to https://github.com/lewissbaker/cppcoro?tab=readme-ov-file#async_generatort

HppZ avatar Apr 22 '24 09:04 HppZ

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.

David-Haim avatar May 14 '24 21:05 David-Haim