Skip to content

execution: Add scheduler-aware overload to as_sender() for P2300 pipe…#7272

Open
shivansh023023 wants to merge 2 commits into
TheHPXProject:masterfrom
shivansh023023:feat/as-sender-executor-context
Open

execution: Add scheduler-aware overload to as_sender() for P2300 pipe…#7272
shivansh023023 wants to merge 2 commits into
TheHPXProject:masterfrom
shivansh023023:feat/as-sender-executor-context

Conversation

@shivansh023023
Copy link
Copy Markdown
Contributor

execution: Add scheduler-aware overload to as_sender()

Extends the as_sender() algorithm to accept an optional scheduler parameter,
allowing HPX futures to be adapted into P2300 senders with full scheduler context.

Proposed Changes

  • Added as_sender_sender_with_scheduler<Future, Scheduler> template
  • Implemented nested env struct following thread_pool_scheduler::sender pattern
  • Two specializations for hpx::future<T> and hpx::shared_future<T>
  • New two-arg operator() on as_sender_t with C++20 requires constraint
  • Scheduler exposed via get_completion_scheduler<set_value_t>()

Enables Pipelines Like

hpx::future<int> f = hpx::async(exec, []{ return 42; });
auto result = stdexec::sync_wait(
    as_sender(std::move(f), get_scheduler(exec))
    | stdexec::then([](int x){ return x * 2; })
);

Context

Checklist

  • I have added a new feature and have added tests to go along with it.

@shivansh023023 shivansh023023 requested a review from hkaiser as a code owner May 16, 2026 10:40
@shivansh023023
Copy link
Copy Markdown
Contributor Author

@hkaiser This extends as_sender() with scheduler context preservation,
building on the get_scheduler bridges from #7238/#7239. The implementation
follows thread_pool_scheduler::sender::env pattern

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 16, 2026

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?

Comment thread libs/core/execution/include/hpx/execution/algorithms/as_sender.hpp Outdated
Comment thread libs/core/execution/include/hpx/execution/algorithms/as_sender.hpp Outdated
@hkaiser hkaiser added type: enhancement type: compatibility issue category: senders/receivers Implementations of the p0443r14 / p2300 + p1897 proposals labels May 16, 2026
@shivansh023023
Copy link
Copy Markdown
Contributor Author

@hkaiser
I have implemented both suggestions
i have Replaced enable_if_t with C++20 requires clause and also deduplicated specializations into single primary template using requires(is_future_v)

Copy link
Copy Markdown
Contributor

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

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

Besides fixing the reported formatting issues, could you please add tests that scrutinize the new functionalities?

@shivansh023023 shivansh023023 force-pushed the feat/as-sender-executor-context branch 3 times, most recently from 199e764 to 7bcc187 Compare May 17, 2026 22:25
…lines

Signed-off-by: Shivansh Singh <singhshivansh023@gmail.com>
@shivansh023023 shivansh023023 force-pushed the feat/as-sender-executor-context branch from 7bcc187 to 7ec40e0 Compare May 17, 2026 22:30
- Replace enable_if_t with C++20 requires clause in constructor
- Deduplicate as_sender_sender_with_scheduler specializations into primary template
- Use requires(is_future_v<Future>) to cover both hpx::future and hpx::shared_future

Signed-off-by: Shivansh <singhshivansh023@gmail.com>
Signed-off-by: Shivansh Singh <singhshivansh023@gmail.com>
@shivansh023023 shivansh023023 force-pushed the feat/as-sender-executor-context branch from 7ec40e0 to b530f78 Compare May 17, 2026 22:34
@shivansh023023
Copy link
Copy Markdown
Contributor Author

@hkaiser

unit tests added covering Basic construction with scheduler context, Environment querying (get_env, get_completion_scheduler), Full P2300 pipeline integration (schedule | then | sync_wait), shared_future variant (both lvalue and move semantics), void-returning futures, Error propagation through exception channel.

@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented May 18, 2026

@hkaiser

unit tests added covering Basic construction with scheduler context, Environment querying (get_env, get_completion_scheduler), Full P2300 pipeline integration (schedule | then | sync_wait), shared_future variant (both lvalue and move semantics), void-returning futures, Error propagation through exception channel.

Unfortunately your new test fails running.

// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/execution.hpp>
#include <hpx/executors/thread_pool_scheduler.hpp>
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.

This will break C++20 module compilation. Please use generated module headers only:

Suggested change
#include <hpx/executors/thread_pool_scheduler.hpp>
#include <hpx/modules/executors.hpp>

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