Iros
 
Loading...
Searching...
No Matches
with_awaitable_senders.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/meta/util.h"
5
6namespace di::execution {
7template<concepts::ClassType Promise>
9public:
10 template<typename OtherPromise>
13 m_continuation = handle;
14
15 if constexpr (requires(OtherPromise& other) {
16 { other.unhandled_stopped() } -> concepts::ConvertibleTo<CoroutineHandle<>>;
17 }) {
18 m_stopped_handler = [](void* address) -> CoroutineHandle<> {
19 return CoroutineHandle<OtherPromise>::from_address(address).promise().unhandled_stopped();
20 };
21 } else {
22 m_stopped_handler = default_unhandled_stopped;
23 }
24
25 if constexpr (requires(OtherPromise& other, Error error) {
26 { other.unhandled_error(util::move(error)) } -> concepts::ConvertibleTo<CoroutineHandle<>>;
27 }) {
28 m_error_handler = [](void* address, Error error) -> CoroutineHandle<> {
29 return CoroutineHandle<OtherPromise>::from_address(address).promise().unhandled_error(
30 util::move(error));
31 };
32 } else {
33 m_error_handler = default_unhandled_error;
34 }
35 }
36
37 auto continuation() const -> CoroutineHandle<> { return m_continuation; }
38 auto unhandled_stopped() -> CoroutineHandle<> { return m_stopped_handler(m_continuation.address()); }
40 return m_error_handler(m_continuation.address(), util::move(error));
41 }
42
43 template<typename Value>
44 auto await_transform(Value&& value) -> decltype(auto) {
45 return as_awaitable(util::forward<Value>(value), static_cast<Promise&>(*this));
46 }
47
48private:
49 [[noreturn]] static auto default_unhandled_stopped(void*) -> CoroutineHandle<> {
50 DI_ASSERT(false);
52 }
53 [[noreturn]] static auto default_unhandled_error(void*, Error) -> CoroutineHandle<> {
54 DI_ASSERT(false);
56 }
57
58 CoroutineHandle<> m_continuation;
59 CoroutineHandle<> (*m_stopped_handler)(void*) { &default_unhandled_stopped };
60 CoroutineHandle<> (*m_error_handler)(void*, Error) { &default_unhandled_error };
61};
62}
63
64namespace di {
66}
#define DI_ASSERT(...)
Definition assert_bool.h:7
Definition with_awaitable_senders.h:8
auto unhandled_error(Error error) -> CoroutineHandle<>
Definition with_awaitable_senders.h:39
auto await_transform(Value &&value) -> decltype(auto)
Definition with_awaitable_senders.h:44
void set_continuation(CoroutineHandle< OtherPromise > handle)
Definition with_awaitable_senders.h:12
auto unhandled_stopped() -> CoroutineHandle<>
Definition with_awaitable_senders.h:38
auto continuation() const -> CoroutineHandle<>
Definition with_awaitable_senders.h:37
Definition operations.h:99
Definition core.h:128
Definition bulk.h:30
constexpr as_awaitable_ns::Function as_awaitable
Definition as_awaitable.h:102
void unreachable()
Definition unreachable.h:4
StatusCode< Erased< long > > Error
Definition error.h:8
Definition zstring_parser.h:9
std::coroutine_handle< Promise > CoroutineHandle
Definition coroutine.h:164