4
4
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_SYNC_WAIT
5
5
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SYNC_WAIT
6
6
7
+ #include < beman/execution26/detail/as_except_ptr.hpp>
7
8
#include < beman/execution26/detail/sender_in.hpp>
8
9
#include < beman/execution26/detail/get_domain_early.hpp>
9
10
#include < beman/execution26/detail/get_scheduler.hpp>
13
14
#include < beman/execution26/detail/start.hpp>
14
15
#include < beman/execution26/detail/run_loop.hpp>
15
16
#include < beman/execution26/detail/receiver.hpp>
17
+ #include < beman/execution26/detail/sender_in.hpp>
18
+ #include < beman/execution26/detail/value_types_of_t.hpp>
19
+ #include < beman/execution26/detail/decayed_tuple.hpp>
16
20
#include < exception>
17
21
#include < optional>
18
22
#include < utility>
23
+ #include < type_traits>
19
24
20
25
// ----------------------------------------------------------------------------
21
26
@@ -28,7 +33,7 @@ namespace beman::execution26::detail
28
33
{
29
34
struct sync_wait_env
30
35
{
31
- ::beman::execution26::run_loop* loop;
36
+ ::beman::execution26::run_loop* loop{} ;
32
37
33
38
auto query (::beman::execution26::get_scheduler_t ) const noexcept
34
39
{
@@ -40,12 +45,24 @@ namespace beman::execution26::detail
40
45
}
41
46
};
42
47
48
+ template <::beman::execution26::sender_in Sender>
49
+ using sync_wait_result_type
50
+ = ::std::optional<
51
+ ::beman::execution26::value_types_of_t <
52
+ Sender,
53
+ ::beman::execution26::detail::sync_wait_env,
54
+ ::beman::execution26::detail::decayed_tuple,
55
+ ::std::type_identity_t
56
+ >
57
+ >;
58
+
43
59
template <typename Sender>
44
60
struct sync_wait_state
45
61
{
46
62
be::run_loop loop{};
47
63
::std::exception_ptr error{};
48
- ::std::optional<int > result{};
64
+
65
+ ::beman::execution26::detail::sync_wait_result_type<Sender> result{};
49
66
};
50
67
51
68
template <typename Sender>
@@ -55,18 +72,30 @@ namespace beman::execution26::detail
55
72
56
73
bed::sync_wait_state<Sender>* state{};
57
74
58
- auto set_error (auto &&) && noexcept -> void
75
+ template <typename Error>
76
+ auto set_error (Error&& error) && noexcept -> void
59
77
{
60
- /* -dk:TODO set state->error */
78
+ this ->state ->error
79
+ = ::beman::execution26::detail::as_except_ptr (
80
+ ::std::forward<Error>(error)
81
+ );
61
82
this ->state ->loop .finish ();
62
83
}
63
84
auto set_stopped () && noexcept -> void
64
85
{
65
86
this ->state ->loop .finish ();
66
87
}
67
- auto set_value (auto &&...) && noexcept -> void
88
+ template <typename ... Args>
89
+ auto set_value (Args&&... args) && noexcept -> void
68
90
{
69
- /* -dk:TODO set state->result */
91
+ try
92
+ {
93
+ this ->state ->result .emplace (::std::forward<Args>(args)...);
94
+ }
95
+ catch (...)
96
+ {
97
+ this ->state ->error = ::std::current_exception ();
98
+ }
70
99
this ->state ->loop .finish ();
71
100
}
72
101
@@ -92,6 +121,18 @@ namespace beman::execution26::detail
92
121
93
122
template <::beman::execution26::sender_in<
94
123
::beman::execution26::detail::sync_wait_env> Sender>
124
+ requires requires (Sender&& sender, sync_wait_t const & self){
125
+ typename ::beman::execution26::detail::sync_wait_result_type<Sender>;
126
+ {
127
+ ::beman::execution26::apply_sender (
128
+ ::beman::execution26::detail::get_domain_early (sender),
129
+ self,
130
+ ::std::forward<Sender>(sender)
131
+ )
132
+ } -> ::std::same_as<
133
+ ::beman::execution26::detail::sync_wait_result_type<Sender>
134
+ >;
135
+ }
95
136
auto operator ()(Sender&& sender) const
96
137
{
97
138
auto domain{::beman::execution26::detail::get_domain_early (sender)};
0 commit comments