• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #847

07 Dec 2022 07:15PM UTC coverage: 85.835% (-0.6%) from 86.482%
#847

push

StellarBot
Merge #6095

6095: Replacing facilities from Boost.Range r=hkaiser a=hkaiser

Working towards #3440 


Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

43 of 43 new or added lines in 21 files covered. (100.0%)

171460 of 199755 relevant lines covered (85.84%)

1820288.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/libs/core/execution/include/hpx/execution/algorithms/ensure_started.hpp
1
//  Copyright (c) 2021 ETH Zurich
2
//  Copyright (c) 2022 Hartmut Kaiser
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#pragma once
9

10
#include <hpx/config.hpp>
11
#include <hpx/allocator_support/internal_allocator.hpp>
12
#include <hpx/allocator_support/traits/is_allocator.hpp>
13
#include <hpx/concepts/concepts.hpp>
14
#include <hpx/execution/algorithms/detail/inject_scheduler.hpp>
15
#include <hpx/execution/algorithms/detail/partial_algorithm.hpp>
16
#include <hpx/execution/algorithms/run_loop.hpp>
17
#include <hpx/execution/algorithms/split.hpp>
18
#include <hpx/execution_base/completion_scheduler.hpp>
19
#include <hpx/execution_base/completion_signatures.hpp>
20
#include <hpx/functional/detail/tag_priority_invoke.hpp>
21

22
#include <exception>
23
#include <memory>
24
#include <utility>
25

26
namespace hpx::execution::experimental {
27

28
    // execution::ensure_started is used to eagerly start the execution of a
29
    // sender, while also providing a way to attach further work to execute once
30
    // it has completed.
31
    //
32
    // Once ensure_started returns, it is known that the provided sender has
33
    // been connected and start has been called on the resulting operation state
34
    // (see 5.2 Operation states represent work); in other words, the work
35
    // described by the provided sender has been submitted for execution on the
36
    // appropriate execution contexts. Returns a sender which completes when the
37
    // provided sender completes and sends values equivalent to those of the
38
    // provided sender.
39
    //
40
    // If the returned sender is destroyed before execution::connect() is
41
    // called, or if execution::connect() is called but the returned
42
    // operation-state is destroyed before execution::start() is called, then a
43
    // stop-request is sent to the eagerly launched operation and the operation
44
    // is detached and will run to completion in the background. Its result
45
    // will be discarded when it eventually completes.
46
    //
47
    // Note that the application will need to make sure that resources are kept
48
    // alive in the case that the operation detaches. e.g. by holding a
49
    // std::shared_ptr to those resources or otherwise having some out-of-band
50
    // way to signal completion of the operation so that resource release can be
51
    // sequenced after the completion.
52
    //
53
    inline constexpr struct ensure_started_t final
54
      : hpx::functional::detail::tag_priority<ensure_started_t>
55
    {
56
    private:
57
        // clang-format off
58
        template <typename Sender,
59
            typename Allocator = hpx::util::internal_allocator<>,
60
            HPX_CONCEPT_REQUIRES_(
61
                is_sender_v<Sender> &&
62
                hpx::traits::is_allocator_v<Allocator> &&
63
                experimental::detail::is_completion_scheduler_tag_invocable_v<
64
                    hpx::execution::experimental::set_value_t,
65
                    Sender, ensure_started_t, Allocator
66
                >
67
            )>
68
        // clang-format on
69
        friend constexpr HPX_FORCEINLINE auto tag_override_invoke(
70
            ensure_started_t, Sender&& sender, Allocator const& allocator = {})
71
        {
72
            auto scheduler =
73
                hpx::execution::experimental::get_completion_scheduler<
74
                    hpx::execution::experimental::set_value_t>(sender);
75

76
            return hpx::functional::tag_invoke(ensure_started_t{},
77
                HPX_MOVE(scheduler), HPX_FORWARD(Sender, sender), allocator);
78
        }
79

80
        // clang-format off
81
        template <typename Sender,
82
            typename Allocator = hpx::util::internal_allocator<>,
83
            HPX_CONCEPT_REQUIRES_(
84
                hpx::execution::experimental::is_sender_v<Sender> &&
85
                hpx::traits::is_allocator_v<Allocator>
86
            )>
87
        // clang-format on
88
        friend constexpr HPX_FORCEINLINE auto tag_invoke(ensure_started_t,
×
89
            hpx::execution::experimental::run_loop_scheduler const& sched,
90
            Sender&& sender, Allocator const& allocator = {})
91
        {
92
            auto split_sender = detail::split_sender<Sender, Allocator,
×
93
                detail::submission_type::eager,
94
                hpx::execution::experimental::run_loop_scheduler>{
95
                HPX_FORWARD(Sender, sender), allocator, sched};
×
96

97
            sched.get_run_loop().run();
×
98
            return split_sender;
×
99
        }
×
100

101
        // clang-format off
102
        template <typename Sender,
103
            typename Allocator = hpx::util::internal_allocator<>,
104
            HPX_CONCEPT_REQUIRES_(
105
                is_sender_v<Sender> &&
106
                hpx::traits::is_allocator_v<Allocator>
107
            )>
108
        // clang-format on
109
        friend constexpr HPX_FORCEINLINE auto tag_fallback_invoke(
18✔
110
            ensure_started_t, Sender&& sender, Allocator const& allocator = {})
111
        {
112
            return detail::split_sender<Sender, Allocator,
18✔
113
                detail::submission_type::eager>{
114
                HPX_FORWARD(Sender, sender), allocator};
18✔
115
        }
116

117
        template <typename Sender, typename Allocator>
118
        friend constexpr HPX_FORCEINLINE auto tag_fallback_invoke(
6✔
119
            ensure_started_t,
120
            detail::split_sender<Sender, Allocator,
121
                detail::submission_type::eager>
122
                sender,
123
            Allocator const& = {})
124
        {
125
            return sender;
6✔
126
        }
127

128
        // clang-format off
129
        template <typename Scheduler, typename Allocator,
130
            HPX_CONCEPT_REQUIRES_(
131
                hpx::execution::experimental::is_scheduler_v<Scheduler> &&
132
                hpx::traits::is_allocator_v<Allocator>
133
            )>
134
        // clang-format on
135
        friend constexpr HPX_FORCEINLINE auto tag_fallback_invoke(
136
            ensure_started_t, Scheduler&& scheduler,
137
            Allocator const& allocator = {})
138
        {
139
            return hpx::execution::experimental::detail::inject_scheduler<
140
                ensure_started_t, Scheduler, Allocator>{
141
                HPX_FORWARD(Scheduler, scheduler), allocator};
142
        }
143

144
        // clang-format off
145
        template <typename Allocator = hpx::util::internal_allocator<>,
146
            HPX_CONCEPT_REQUIRES_(
147
                hpx::traits::is_allocator_v<Allocator>
148
            )>
149
        // clang-format on
150
        friend constexpr HPX_FORCEINLINE auto tag_fallback_invoke(
17✔
151
            ensure_started_t, Allocator const& allocator = {})
152
        {
153
            return detail::partial_algorithm<ensure_started_t, Allocator>{
17✔
154
                allocator};
17✔
155
        }
156
    } ensure_started{};
157
}    // namespace hpx::execution::experimental
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc