Skip to content

Implement P2300 stopped_as_optional sender adapter#7243

Open
shivansh023023 wants to merge 1 commit intoTheHPXProject:masterfrom
shivansh023023:feat/p2300-stopped-as-optional
Open

Implement P2300 stopped_as_optional sender adapter#7243
shivansh023023 wants to merge 1 commit intoTheHPXProject:masterfrom
shivansh023023:feat/p2300-stopped-as-optional

Conversation

@shivansh023023
Copy link
Copy Markdown
Contributor

Implement P2300 stopped_as_optional sender adapter

Description

This PR implements the stopped_as_optional sender adapter as defined in the P2300 (Sender/Receiver) standard. This utility is crucial for handling pipeline cancellations gracefully by converting a "stopped" signal into a successful "value" signal containing a std::nullopt.

Technical Implementation:

  • Three-Channel Mapping:
    • Value Channel: Wraps the result T into std::optional<T>.
    • Stopped Channel: Intercepted and rerouted to set_value(std::nullopt).
    • Error Channel: Passed through to the next receiver without modification.
  • Lifecycle & Metadata: Correctly sets sends_stopped = false since the stopped signal is consumed by the adapter.
  • Environment Support: Implements get_env forwarding to ensure context and completion schedulers are preserved across the pipeline.
  • Syntax: Full support for both functional calling and the pipe (|) operator via partial_algorithm.

Fixes #

Proposed Changes

  • Added libs/core/execution/include/hpx/execution/algorithms/stopped_as_optional.hpp.
  • Added libs/core/execution/tests/unit/algorithm_stopped_as_optional.cpp covering value, error, and stopped scenarios.
  • Registered the new unit test in libs/core/execution/tests/unit/CMakeLists.txt.

Background context

Currently, HPX's P2300 implementation requires manual handling of stopped signals which can lead to complex and verbose pipeline logic. Adding stopped_as_optional provides a standardized, ergonomic way to treat cancellation as a state rather than a control-flow break.

Checklist

  • I have added a new feature and have added tests to go along with it.
  • I have verified the build and runtime success locally (Exit Code 0).
  • I have maintained original copyright headers and ensured alphabetical include ordering for inspect tool compliance.

- Added stopped_as_optional to transform stopped signals into value(nullopt)
- Implemented sender, receiver, and operation state for the transformation
- Provided support for piping syntax via partial_algorithm
- Forwarded environment and completion scheduler from predecessor
- Added comprehensive unit tests for value, error, and stopped paths
@shivansh023023 shivansh023023 requested a review from hkaiser as a code owner May 3, 2026 14:56
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@StellarBot
Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@hkaiser hkaiser added category: senders/receivers Implementations of the p0443r14 / p2300 + p1897 proposals type: enhancement type: compatibility issue labels May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: senders/receivers Implementations of the p0443r14 / p2300 + p1897 proposals type: compatibility issue type: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants