Boost logo

Boost :

Subject: Re: [boost] [coroutine] Experimenting with interfaces
From: Eugene Yakubovich (eyakubovich_at_[hidden])
Date: 2012-09-21 14:45:14


On Fri, Sep 21, 2012 at 1:34 PM, Oliver Kowalke <oliver.kowalke_at_[hidden]> wrote:
>>>
>>> template <typename C>
>>> void timer(C c, chrono::seconds interval) {
>>> // while( interval != chrono::seconds::zero() ) {
>>> // this_thread::sleep_for(interval);
>>> // interval = c(interval);
>>> // }
>>>
>>> }
>>>
>>> coroutine<chrono::seconds(chrono::seconds)> c(
>>> [](coroutine<chrono::seconds(chrono::seconds)> c, chrono::seconds i)
>>> {
>>> timer(c, i);
>>> }
>>> );
>>>
>>> chrono::seconds s = c(chrono::seconds(1));
>>>
>>>
>>> Which value has variable 's' after return from 'c(chrono::seconds(1))' ?
>>
>> chrono::seconds(1) since timer() yields whatever was initially passed
>> in and then whatever was returned by c().
>>
> in the modified example timer() never yields (c(interval) is not called) -
> it simple returns.
> no value was transfered from coroutine function to the caller -> coroutines
> must return the type of the signature

Ok, I understand now. Like Giovanni mentioned in his response, an
exception can be used (just like your current implementation throws
coroutine_terminated). There might be a better way, I don't know. I
wouldn't want to use optional<> here as it would then not be
inter-operable with a regular function. In case of generator<>,
optional<T> is OK since generators are not meant to be symmetric. I
must admit that during this exercise I was looking for desirable
features but I didn't think the behavior all the way through.

Regards,
Eugene.


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