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

Fix the preconditoins in the library docs #119

Open
akrzemi1 opened this issue Sep 24, 2023 · 0 comments
Open

Fix the preconditoins in the library docs #119

akrzemi1 opened this issue Sep 24, 2023 · 0 comments

Comments

@akrzemi1
Copy link
Member

Promise and Generator state that on get() exception is thrown if not ready:
https://klemens.dev/async/reference.html#generator-outline
https://klemens.dev/async/reference.html#promise-outline

Are you consciously giving such guarantee? I would expect that to be a precondition on get(): call it only if ready() == true.

But you should also explain what it means that a result is ready. For instance, when the coroutine threw an exception and it has not been inspected yet by the awaiter, is "result ready"?

The throwing of std::logic_error is a poor design choice (also employed in the Standard Library) as it sends a mixed message. Is it a programmer bug when I do that? Or is it something that I can expect deterministic results for?

I would call it a precondition and use BOOST_ASSERT in the implementation, and if the user wishes to throw std::logic_error, let them install an assertion handler.

For other functions like async::thread::detach() the library doesn't specify at all what happens if I call .detach() twice. Does .detach() have a precondition that this->joinable() == true?

Also, what happens when I co_await ona promise p whose operator bool returns false? Is it a contract violation?

What is the precondition on co_await p? is it p.ready() or p. operator bool()? How are they different?

I should be able to figure out these answers from the documentaiton.

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

1 participant