Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coro<int,int> return maby error #1528

Open
kahotv opened this issue Sep 20, 2024 · 1 comment
Open

coro<int,int> return maby error #1528

kahotv opened this issue Sep 20, 2024 · 1 comment

Comments

@kahotv
Copy link

kahotv commented Sep 20, 2024

When using coro<int,int>, the return type is not the expected variant<int,int>, but actually int.

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

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.)

@klemens-morgenstern
Copy link
Contributor

That's by design (just missing proper docs). This is mean for when a return may indicate the error by it's value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants