Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2023-08-17 22:50:37


czw., 17 sie 2023 o 23:55 Ruben Perez <rubenperez038_at_[hidden]> napisał(a):

> > One more question. This interface of async::generator<Out, In>, taking
> two
> > parameters, where one can not only generate values from the generator,
> but
> > also obtain values: is there a real-life use case for this?
>
> I'd say major languages like Python and JS allow for this, too.
> So if you're coming from these, it makes sense.
>

Thanks, but still,
could someone show a plausible real-life example of this written in
Boost.Asynch?
I am not familiar with Python's or JS's coroutines. But do they have an
*identical* interface?

When I was trying to come up with an example, I found the results
surprising:

auto output1 = co_await generator(input1);
auto output2 = co_await generator(input2);

I expected that this instruction would mean "take input2, suspend, and when
resumed return value computed from input2". But because the implementation
in the coroutine has to read:

auto next_input = co_yield compute(input);

The consequence is that the co_awaits actually mean "take input2, suspend,
and when resumed return value computed from input1".

Maybe I am doing something wrong, I would like to be corrected. The
argument that other languages have it is not a valid one for me. I would
still like to know if this has a use case when implemented as it is with
C++ coroutines.

I enclose my example, where I tried to model a producer and consumer
situation, and concluded that I couldn't.

Regards,
&rzej;




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