Boost logo

Boost :

From: Klemens Morgenstern (klemensdavidmorgenstern_at_[hidden])
Date: 2023-09-24 00:39:15


On Sun, Sep 24, 2023, 3:51 AM Andrzej Krzemienski via Boost <
boost_at_[hidden]> wrote:

> Hi Everyone.
> I am very uneasy about the dummy co_retuned value that I see in the
> examples of async::generator. Like the one in the echo server example:
> https://klemens.dev/async/tutorial.html#echo_server
>
> async::generator<tcp_socket> listen()
> {
> tcp_acceptor acceptor({co_await async::this_coro::executor}, {tcp::v4(),
> 55555});
> for (;;)
> {
> tcp_socket sock = co_await acceptor.async_accept();
> co_yield std::move(sock);
> }
> co_return tcp_socket{acceptor.get_executor()}; // :-(
> }
>
> The control will never get to the co_return. The caller never even tries to
> observe this value. and yet we are forced to return it.
>

You can throw a dummy exception, too. Never gets executed anyhow.

>
> Interestingly, the coroutine example from ASIO doesn't have this due to a
> different design:
>
> https://www.boost.org/doc/libs/1_83_0/doc/html/boost_asio/example/cpp20/coroutines/echo_server.cpp
>
>
>
> std::generator doesn't have this.
>
> In other examples the degenerate value is used to indicate the end of
> generation.
>
> I do not know the coroutines to be able to tell if this is a design problem
> with async::generator or with C++ coroutines in general. But it feels wrong
>

Why? How would you want to communicate to the awaiter that the coro is done?

that the end of generation should be signaled in this way.
>
> Regards,
> &rzej;
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk