refactor channel push and pop return values#79
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors condy::Channel to use errno-style integer return codes for both synchronous (try_push/try_pop) and coroutine (push/pop) operations, and updates tests/docs accordingly while introducing a deprecated legacy channel API for the previous behavior.
Changes:
- Change
Channelpush/pop APIs to returnint/(int, T)results (e.g.,0,-EAGAIN,-EPIPE,-ECANCELED) instead ofbool/optional/exceptions. - Update channel-related tests to match the new return types and error codes.
- Add
condy::legacy::Channel(deprecated) and update guide/benchmark code for the new API.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| include/condy/channel.hpp | Refactors Channel API and awaiter completion to use errno-style results; includes legacy header. |
| include/condy/channel_legacy.hpp | Adds deprecated legacy channel implementation preserving prior semantics. |
| tests/test_channel.cpp | Updates channel unit tests to the new return conventions. |
| tests/test_async_operations.1.cpp | Adjusts channel pop usage in async recvmsg multishot test to new return type. |
| tests/test_async_operations.2.cpp | Adjusts channel push/pop usage in async read multishot tests to new return type. |
| tests/test_async_operations.3.cpp | Adjusts channel push/pop usage in async recv multishot tests to new return type. |
| docs/guide.md | Updates guide examples to new channel pop contract and closes channel in producer example. |
| benchmarks/channel.cpp | Updates benchmark consumer to destructure new pop return type. |
Comments suppressed due to low confidence (1)
tests/test_channel.cpp:370
- This test still relies on
item == 0to detect a closed channel, but the refactor makespop()return an explicit error code. Please checkr == 0for the firstmax_itemspops, and then assertr == -EPIPEafterpush_close()(instead of relying on a default value) so the test matches the new API semantics.
auto consumer = [&]() -> condy::Coro<void> {
for (size_t i = 0; i < 2 * max_items; ++i) {
auto [r, item] = co_await channel.pop();
if (i < max_items) {
REQUIRE(item == static_cast<int>(i + 1));
} else {
REQUIRE(item == 0); // Default indicates closed channel
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.