PS D:\workspace\git\vcpkg> .\vcpkg.exe list
...
asio:x86-windows-static 1.30.2
code
coro<int,int> generator_int(any_io_executor)
{
int i = 0;
do
{
co_yield i++;
} while (i < 3);
co_return 0;
}
awaitable<void> test_print()
{
auto g = generator_int(co_await this_coro::executor);
while (g)
{
auto ret = co_await g.async_resume(use_awaitable);
printf("type=%s, value=%d\n", typeid(ret).name(), ret);
}
printf("end\n");
}
int main(int argc, char** argv)
{
io_context ctx;
co_spawn(ctx, test_print(), detached);
ctx.run();
}
output:
type=int, value=0
type=int, value=1
type=int, value=2
type=int, value=0
end
This makes it impossible for me to determine whether the return value comes from co_yield or co_return.
(The use of coro<int> is correct, and the return type is optional<int> as expected.)
When using
coro<int,int>
, the return type is not the expectedvariant<int,int>
, but actuallyint
.see https://think-async.com/Asio/asio-1.30.2/doc/asio/overview/composition/coro.html#asio.overview.composition.coro.result
version 1.30.2
code
output:
This makes it impossible for me to determine whether the return value comes from
co_yield
orco_return
.(The use of
coro<int>
is correct, and the return type isoptional<int>
as expected.)