Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions include/beman/task/detail/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ namespace beman::task::detail {
template <typename P>
class handle {
private:
using deleter = decltype([](auto p) {
if (p) {
std::coroutine_handle<P>::from_promise(*p).destroy();
struct deleter {
auto operator()(P* p) noexcept -> void {
if (p) {
std::coroutine_handle<P>::from_promise(*p).destroy();
}
}
});
};
std::unique_ptr<P, deleter> h;

public:
Expand Down
23 changes: 13 additions & 10 deletions include/beman/task/detail/into_optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ inline constexpr struct into_optional_t : beman::execution::sender_adaptor_closu
}

template <typename Env>
auto get_type(Env&&) const {
static auto get_type(Env&&) {
return find_type(
::beman::execution::value_types_of_t<Upstream, std::remove_cvref_t<Env>, type_list, type_list>());
}
Expand All @@ -69,18 +69,21 @@ inline constexpr struct into_optional_t : beman::execution::sender_adaptor_closu
type_list<::beman::execution::set_stopped_t()>,
type_list<>>{});
}

template <typename Receiver>
struct make_object {
template <typename... A>
auto
operator()(A&&... a) const -> decltype(get_type(::beman::execution::get_env(std::declval<Receiver>()))) {
if constexpr (sizeof...(A) == 0u)
return {};
else
return {std::forward<A>(a)...};
}
};
template <typename Receiver>
auto connect(Receiver&& receiver) && {
return ::beman::execution::connect(
::beman::execution::then(
std::move(this->upstream),
[]<typename... A>(A&&... a) -> decltype(get_type(::beman::execution::get_env(receiver))) {
if constexpr (sizeof...(A) == 0u)
return {};
else
return {std::forward<A>(a)...};
}),
::beman::execution::then(std::move(this->upstream), make_object<Receiver>{}),
std::forward<Receiver>(receiver));
}
};
Expand Down
5 changes: 4 additions & 1 deletion include/beman/task/detail/single_thread_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_SINGLE_THREAD_CONTEXT

#include <beman/execution/execution.hpp>
#include <functional>
#include <thread>

// ----------------------------------------------------------------------------
Expand All @@ -13,7 +14,9 @@ namespace beman::task::detail {
class single_thread_context {
private:
::beman::execution::run_loop loop;
::std::thread thread{[this] { this->loop.run(); }};
::std::thread thread{&single_thread_context::run, this};

static auto run(single_thread_context* self) -> void { self->loop.run(); }

public:
single_thread_context() = default;
Expand Down
Loading