-
-
Notifications
You must be signed in to change notification settings - Fork 543
execution: Add scheduler-aware overload to as_sender() for P2300 pipe… #7272
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
Open
shivansh023023
wants to merge
2
commits into
TheHPXProject:master
Choose a base branch
from
shivansh023023:feat/as-sender-executor-context
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
111 changes: 111 additions & 0 deletions
111
libs/core/execution/tests/unit/algorithm_as_sender_with_scheduler.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright (c) 2026 The STE||AR-Group | ||
| // | ||
| // SPDX-License-Identifier: BSL-1.0 | ||
| // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| // 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> | ||
| #include <hpx/future.hpp> | ||
| #include <hpx/init.hpp> | ||
| #include <hpx/modules/futures.hpp> | ||
| #include <hpx/modules/testing.hpp> | ||
|
|
||
| namespace ex = hpx::execution::experimental; | ||
| namespace tt = hpx::this_thread::experimental; | ||
|
|
||
| void test_as_sender_with_scheduler_basic() | ||
| { | ||
| // Test: future + scheduler -> sender with env | ||
| auto f = hpx::async([] { return 42; }); | ||
| ex::thread_pool_scheduler sched{}; | ||
| auto sender = ex::as_sender(std::move(f), sched); | ||
| // Verify compilation and basic properties | ||
| (void) sender; | ||
| } | ||
|
|
||
| void test_as_sender_with_scheduler_get_env() | ||
| { | ||
| // Test: env exposes the scheduler | ||
| auto f = hpx::async([] { return 42; }); | ||
| ex::thread_pool_scheduler sched{}; | ||
| auto sender = ex::as_sender(std::move(f), sched); | ||
| auto env = ex::get_env(sender); | ||
| // Verify env can be queried for scheduler | ||
| auto sched_from_env = ex::get_completion_scheduler<ex::set_value_t>(env); | ||
| HPX_TEST(sched == sched_from_env); | ||
| } | ||
|
|
||
| void test_as_sender_with_scheduler_in_pipeline() | ||
| { | ||
| // Full end-to-end test | ||
| auto f = hpx::async([] { return 42; }); | ||
| ex::thread_pool_scheduler sched{}; | ||
|
|
||
| auto [result] = | ||
| tt::sync_wait(ex::as_sender(std::move(f), sched) | ex::then([](int x) { | ||
| return x * 2; | ||
| })).value(); | ||
|
|
||
| HPX_TEST_EQ(result, 84); | ||
| } | ||
|
|
||
| void test_as_sender_with_scheduler_shared_future() | ||
| { | ||
| // Test shared_future variant (copyable) | ||
| auto f = hpx::make_shared_future(hpx::async([] { return 42; })); | ||
| ex::thread_pool_scheduler sched{}; | ||
| auto sender = ex::as_sender(f, sched); // f is lvalue, not moved | ||
|
|
||
| auto [result] = | ||
| tt::sync_wait(sender | ex::then([](int x) { return x * 2; })).value(); | ||
|
|
||
| HPX_TEST_EQ(result, 84); | ||
| } | ||
|
|
||
| void test_as_sender_with_scheduler_void() | ||
| { | ||
| // Test void-returning futures | ||
| bool executed = false; | ||
| auto f = hpx::async([&] { executed = true; }); | ||
| ex::thread_pool_scheduler sched{}; | ||
| auto sender = ex::as_sender(std::move(f), sched); | ||
| tt::sync_wait(std::move(sender)); | ||
| HPX_TEST(executed); | ||
| } | ||
|
|
||
| void test_as_sender_with_scheduler_error() | ||
| { | ||
| // Test exception propagation | ||
| auto f = hpx::async([]() -> int { | ||
| throw std::runtime_error("test error"); | ||
| return 42; | ||
| }); | ||
| ex::thread_pool_scheduler sched{}; | ||
| auto sender = ex::as_sender(std::move(f), sched); | ||
|
|
||
| bool caught = false; | ||
| try | ||
| { | ||
| tt::sync_wait(std::move(sender)); | ||
| HPX_TEST(false); // Should have thrown | ||
| } | ||
| catch (std::runtime_error const& e) | ||
| { | ||
| caught = true; | ||
| HPX_TEST_EQ(std::string(e.what()), "test error"); | ||
| } | ||
| HPX_TEST(caught); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| test_as_sender_with_scheduler_basic(); | ||
| test_as_sender_with_scheduler_get_env(); | ||
| test_as_sender_with_scheduler_in_pipeline(); | ||
| test_as_sender_with_scheduler_shared_future(); | ||
| test_as_sender_with_scheduler_void(); | ||
| test_as_sender_with_scheduler_error(); | ||
|
|
||
| return hpx::util::report_errors(); | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
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: