Iros
 
Loading...
Searching...
No Matches
scope.h
Go to the documentation of this file.
1#pragma once
2
13#include "di/meta/operations.h"
14#include "di/meta/vocab.h"
17
18namespace di::execution {
19namespace request_stop_ns {
20 template<typename Scope>
21 concept MemberInvocable = requires(meta::UnwrapReference<Scope>& scope) { scope.request_stop(); };
22
23 struct Function {
24 template<typename Scope>
26 auto operator()(Scope& scope) const -> bool {
27 if constexpr (MemberInvocable<Scope>) {
28 static_assert(concepts::BooleanTestable<decltype(unwrap_reference(scope).request_stop())>,
29 "request_stop() member function must return a boolean.");
30 return unwrap_reference(scope).request_stop();
31 } else {
33 "request_stop() customizations must return a boolean.");
34 return tag_invoke(*this, unwrap_reference(scope));
35 }
36 }
37 };
38}
39
48constexpr inline auto request_stop = request_stop_ns::Function {};
49
50namespace nest_ns {
51 struct Function {
52 template<typename Scope, concepts::Sender Send>
54 auto operator()(Scope& scope, Send&& sender) const {
56 "nest() customizations must return a Sender.");
57 return tag_invoke(*this, unwrap_reference(scope), util::forward<Send>(sender));
58 }
59 };
60}
61
84constexpr inline auto nest = nest_ns::Function {};
85
86namespace spawn_ns {
87 struct Function {
88 template<typename Scope, concepts::NextSender<meta::EnvOf<Scope>> Send>
89 auto operator()(Scope& scope, Send&& sender) const {
91 static_assert(
93 void>,
94 "spawn() customizations must return a maybe fallible void.");
95 return tag_invoke(*this, unwrap_reference(scope), util::forward<Send>(sender));
96 } else {
97 auto allocator = get_allocator(get_env(scope));
98 return start_detached(nest(scope, util::forward<Send>(sender)), util::move(allocator));
99 }
100 }
101 };
102}
103
129constexpr inline auto spawn = spawn_ns::Function {};
130
132 struct Function {
133 template<typename Scope, concepts::SenderIn<meta::EnvOf<Scope>> Send>
134 auto operator()(Scope& scope, Send&& sender) const {
136 static_assert(
139 "nest() customizations must return a maybe fallible Sender.");
140 return tag_invoke(*this, unwrap_reference(scope), util::forward<Send>(sender));
141 } else {
142 auto allocator = get_allocator(get_env(scope));
143 return ensure_started(nest(scope, util::forward<Send>(sender)), util::move(allocator));
144 }
145 }
146 };
147}
148
169constexpr inline auto spawn_future = spawn_future_ns::Function {};
170
179template<typename T>
180concept Scope = requires(T& scope) {
181 request_stop(scope);
182 nest(scope, stopped);
183 spawn(scope, stopped);
184 spawn_future(scope, stopped);
185};
186}
Definition operations.h:128
Definition vocab.h:74
Definition sender.h:11
Definition tag_invoke.h:33
A type which models an async scope.
Definition scope.h:180
Definition scope.h:50
Definition scope.h:19
Definition scope.h:131
Definition scope.h:86
Definition bulk.h:30
constexpr auto ensure_started
Eagerly start a sender.
Definition ensure_started.h:333
constexpr auto stopped
Definition just.h:91
constexpr auto spawn
Spawn a sender inside a scope.
Definition scope.h:129
constexpr auto start_detached
Start a sender without waiting for it to complete.
Definition start_detached.h:134
constexpr auto request_stop
Request that a scope stop.
Definition scope.h:48
constexpr auto spawn_future
Spawn a sender inside a scope, and return a future to the result.
Definition scope.h:169
constexpr auto get_env
Definition get_env.h:27
constexpr auto get_allocator
Definition get_allocator.h:27
constexpr auto nest
Nest a sender inside a scope.
Definition scope.h:84
Invoke< Conditional< concepts::Expected< T >, meta::Quote< ExpectedValue >, meta::TypeConstant< T > >, T > UnwrapExpected
Definition vocab.h:63
detail::UnwrapReferenceHelper< T >::Type UnwrapReference
Definition vocab.h:127
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
constexpr auto unwrap_reference
Definition unwrap_reference.h:20
Defines the sequence sender concepts and related CPOs.
auto operator()(Scope &scope, Send &&sender) const
Definition scope.h:134
auto operator()(Scope &scope, Send &&sender) const
Definition scope.h:89