Skip to content

Commit 2311d49

Browse files
committed
make the static_thread_pool scheduler conditionally infallible
1 parent 3518e31 commit 2311d49

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

include/exec/execute.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,26 @@ namespace exec {
3030
/////////////////////////////////////////////////////////////////////////////
3131
// [execution.execute]
3232
struct __execute_t {
33-
template <STDEXEC::scheduler _Scheduler, class _Fun>
34-
requires STDEXEC::__callable<_Fun&> && STDEXEC::__std::move_constructible<_Fun>
33+
template <STDEXEC::scheduler _Scheduler, STDEXEC::__std::move_constructible _Fun>
34+
requires STDEXEC::__callable<_Fun&>
3535
void operator()(_Scheduler&& __sched, _Fun __fun) const noexcept(false) {
3636
auto __domain = STDEXEC::get_domain(__sched);
3737
STDEXEC::apply_sender(
38-
__domain, *this, STDEXEC::schedule(static_cast<_Scheduler&&>(__sched)), static_cast<_Fun&&>(__fun));
38+
__domain,
39+
*this,
40+
STDEXEC::schedule(static_cast<_Scheduler&&>(__sched)),
41+
static_cast<_Fun&&>(__fun));
3942
}
4043

41-
template <STDEXEC::sender_of<STDEXEC::set_value_t()> _Sender, class _Fun>
42-
requires STDEXEC::__callable<_Fun&> && STDEXEC::__std::move_constructible<_Fun>
44+
template <STDEXEC::sender _Sender, STDEXEC::__std::move_constructible _Fun>
45+
requires STDEXEC::__callable<_Fun&>
46+
&& STDEXEC::__callable<
47+
start_detached_t,
48+
STDEXEC::__result_of<STDEXEC::then, _Sender, _Fun>
49+
>
4350
void apply_sender(_Sender&& __sndr, _Fun __fun) const noexcept(false) {
44-
exec::start_detached(STDEXEC::then(static_cast<_Sender&&>(__sndr), static_cast<_Fun&&>(__fun)));
51+
exec::start_detached(
52+
STDEXEC::then(static_cast<_Sender&&>(__sndr), static_cast<_Fun&&>(__fun)));
4553
}
4654
};
4755

@@ -51,4 +59,3 @@ namespace exec {
5159
[[deprecated]]
5260
inline constexpr const __execute_t& execute = __execute;
5361
} // namespace exec
54-

include/exec/static_thread_pool.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,14 @@ namespace exec {
335335
template <class Receiver>
336336
using _opstate_t = _opstate<Receiver>;
337337

338-
using completion_signatures =
339-
STDEXEC::completion_signatures<set_value_t(), set_stopped_t()>;
338+
template <class _Self, class _Env>
339+
static consteval auto get_completion_signatures() noexcept {
340+
if constexpr (unstoppable_token<stop_token_of_t<_Env>>) {
341+
return STDEXEC::completion_signatures<set_value_t()>();
342+
} else {
343+
return STDEXEC::completion_signatures<set_value_t(), set_stopped_t()>();
344+
}
345+
}
340346

341347
[[nodiscard]]
342348
auto get_env() const noexcept -> env {

0 commit comments

Comments
 (0)