Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does concurrencpp support "co_yield co_await xxx" in generator? #162

Open
HppZ opened this issue Apr 19, 2024 · 5 comments
Open

Does concurrencpp support "co_yield co_await xxx" in generator? #162

HppZ opened this issue Apr 19, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@HppZ
Copy link

HppZ commented Apr 19, 2024

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 HppZ changed the title Does concurrencpp support co_yield co_await in generator? Does concurrencpp support "co_yield co_await" in generator? Apr 19, 2024
@HppZ HppZ changed the title Does concurrencpp support "co_yield co_await" in generator? Does concurrencpp support "co_yield co_await xxx" in generator? Apr 19, 2024
@HppZ HppZ closed this as completed Apr 19, 2024
@HppZ HppZ reopened this Apr 22, 2024
@HppZ
Copy link
Author

HppZ commented Apr 22, 2024

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

@HppZ
Copy link
Author

HppZ commented Apr 22, 2024

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
Copy link
Author

HppZ commented Apr 22, 2024

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

@HppZ
Copy link
Author

HppZ commented Apr 22, 2024

@David-Haim David-Haim added the enhancement New feature or request label May 14, 2024
@David-Haim
Copy link
Owner

David-Haim commented May 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants