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

Use std::expected instead of std::error_code reference #11

Conversation

Jacquwes
Copy link
Owner

PR Classification

API change to modernize and simplify error handling.

PR Summary

Refactored codebase to use std::expected and async_operation with std::error_code for improved error handling.

  • client_connection.h and client_connection.cpp: Switched to async_operation with std::error_code.
  • server.h and server.cpp: Adopted std::expected for error handling.
  • coroutine.h: Replaced async_task with async_operation using std::expected.
  • client_example.cpp and server_example.cpp: Updated main function for new error handling.
  • CMakeLists.txt: Included new expected.h header file.

closes: #10

Updated `receive_raw_message` and `send_raw_message` methods in the `connection` class to return `async_operation` with `std::error_code`. This change eliminates the need to pass error codes by reference. Implemented error handling using `co_return` with `std::make_error_code`. Added a check in `send_raw_message` to ensure message size matches bytes sent. Included `error.h` in `connection.cpp`.
Replaced individual `using` declarations for `tl::unexpected`,
`tl::expected`, `tl::make_unexpected`, and `tl::swap` with a
single `using namespace tl;` statement within the `std` namespace.
This change reduces redundancy and makes the code cleaner and
easier to maintain.
@Jacquwes Jacquwes merged commit 3bda6c8 into master Sep 16, 2024
0 of 2 checks passed
@Jacquwes Jacquwes deleted the 10-use-stdexpected-as-return-type-instead-of-passing-error_code-reference branch September 16, 2024 21:19
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

Successfully merging this pull request may close these issues.

Use std::expected as return type instead of passing error_code reference
1 participant