
Am 21.09.2012 20:15, schrieb Eugene Yakubovich:
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