Skip to content

Updating channel to be mpsc#83

Merged
adityarao2005 merged 3 commits into
mainfrom
updating-channel-to-be-mpsc
Mar 22, 2026
Merged

Updating channel to be mpsc#83
adityarao2005 merged 3 commits into
mainfrom
updating-channel-to-be-mpsc

Conversation

@adityarao2005

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 22, 2026 16:24
@vercel

vercel Bot commented Mar 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web-craft-docs Ready Ready Preview, Comment Mar 22, 2026 4:42pm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the async I/O “channel” implementation to behave as a multi-producer/single-consumer (MPSC) channel with explicit close semantics, and adds tests to validate multi-producer behavior (including cross-thread sends).

Changes:

  • Add mutex-protected state to mpsc_channel_subscription and introduce close() to wake a blocked receiver and signal end-of-stream.
  • Extend mpsc_channel_wstream with an async close() API and add static-assert coverage for the closeable-stream concept.
  • Add new unit tests covering multi-producer message delivery and thread-pool-based producers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
include/webcraft/async/io/core.hpp Makes MPSC channel state thread-safe, adds close support, and updates awaitable behavior to return std::optional<T>.
tests/src/test_async_io_core.cpp Adds new tests for multi-producer and thread-safe MPSC channel usage, plus required includes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/webcraft/async/io/core.hpp
Comment thread include/webcraft/async/io/core.hpp Outdated
Comment thread include/webcraft/async/io/core.hpp Outdated
Refactor to use std::move for efficiency in value handling.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/webcraft/async/io/core.hpp
Comment on lines +361 to +370
auto run_producers_and_close = [&]() -> task<void>
{
std::vector<task<void>> producers;

std::vector<std::string> messages{expected_messages.begin(), expected_messages.end()};

for (const auto &message : messages)
{
producers.push_back(producer_one(message));
}

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_producers_and_close builds messages from expected_messages while consumer_fn concurrently erases from expected_messages. This is an unsynchronized cross-task access to the same std::unordered_set, which is undefined behavior (iterator invalidation / data race). Generate messages from an independent source (e.g., the same iota range) or build messages/expected_messages completely before starting the consumer task.

Copilot uses AI. Check for mistakes.
auto producer_one = [writer, &pool](std::string message1) mutable -> task<void>
{
co_await threaded_awaitable{pool};
auto check = co_await writer.send(message1);

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In producer_one, writer.send(message1) passes an lvalue std::string, causing an extra copy into send(T val) (and then a move). Use std::move(message1) when calling send to avoid the redundant copy, especially since this test sends 1000 messages.

Suggested change
auto check = co_await writer.send(message1);
auto check = co_await writer.send(std::move(message1));

Copilot uses AI. Check for mistakes.
sync_wait(task_fn());
}

TEST_CASE(MpScChannel)

Copilot AI Mar 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case name MpScChannel looks like a typo/inconsistent acronym casing for an MPSC channel. Consider renaming to something unambiguous like MpscChannel/MPSCChannel to match the channel type (make_mpsc_channel).

Suggested change
TEST_CASE(MpScChannel)
TEST_CASE(MpscChannel)

Copilot uses AI. Check for mistakes.
@adityarao2005 adityarao2005 merged commit 7384767 into main Mar 22, 2026
10 of 11 checks passed
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.

2 participants