coroutine 2


Goal: see coroutineYieldTest()
We get promise.mValue by calling hRange.resume().

How it’s achieved:
coroutine_handle hRange is from CReturnObjGen, which is the return from calling cofuncYield.
Coroutine cofuncYield() has a loop that keeps calling co_yield to return an integer.
Different from coroutine-1 in last post, CReturnObjGen has no base class.
It has to implement subclass promise_type.
The yield value promise.mValue is passed in by promise.yield_value(value)
CReturnObjGen holds the handle in mhCoroutine, which is passed in by ctor, which is somehow called.
cofuncYield(): upon each trigger, it passes co_yield and then loops back and block.
has no return statement even though it has return type.

Download: http://riowing.net/p/wp/coroutine.cpp

coroutine 1


Goal: see Test_generator
We get value by calling hReturnGen’s iterator, as a container like vector.
hReturnGen is the return when the coroutine is called.

How it’s achieved:
Coroutine cofunc_generator() has a loop that keeps calling co_yield to return an integer.
hReturnGen is based on experimental::generator, which does the heavy lifting.

A peek inside:
The iterator can come from :generator.begin()
iterator._Coro.promise()._Value holds the yield value
_Coro is the coroutine handle.

Download: http://riowing.net/p/wp/coroutine.cpp