MayaFlux
0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GetPromise.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
MayaFlux/Vruta/Promise.hpp
"
4
5
namespace
MayaFlux::Kriya
{
6
7
/**
8
* @struct GetPromiseBase
9
* @brief Templated awaitable for accessing a coroutine's promise object
10
*
11
* This template allows coroutines to access their own promise object in a
12
* type-safe, domain-agnostic way. Each domain (audio, graphics, complex, event)
13
* can instantiate this template with their specific promise type.
14
*
15
* @tparam PromiseType The promise type to access (audio_promise, graphics_promise, etc.)
16
*/
17
template
<
typename
PromiseType>
18
struct
MAYAFLUX_API
GetPromiseBase
{
19
using
promise_handle
= PromiseType;
20
21
/**
22
* @brief Pointer to store the promise object
23
*
24
* This field is set during await_suspend and returned by
25
* await_resume, providing the coroutine with access to its
26
* own promise object.
27
*/
28
promise_handle
* promise_ptr =
nullptr
;
29
30
GetPromiseBase
() =
default
;
31
32
[[nodiscard]]
inline
bool
await_ready
() const noexcept
33
{
34
return
false
;
35
}
36
37
void
await_suspend
(std::coroutine_handle<promise_handle> h)
noexcept
38
{
39
promise_ptr = &h.promise();
40
h.promise().active_delay_context = Vruta::DelayContext::AWAIT;
41
}
42
43
[[nodiscard]]
promise_handle
&
await_resume
() const noexcept
44
{
45
return
*promise_ptr;
46
}
47
};
48
49
/**
50
* @brief Audio domain promise accessor
51
*
52
* Usage in SoundRoutine:
53
* ```cpp
54
* auto routine = []() -> SoundRoutine {
55
* auto& promise = co_await GetPromise{};
56
* // or explicitly: co_await GetAudioPromise{};
57
* // promise is audio_promise&
58
* };
59
* ```
60
*/
61
using
GetAudioPromise
=
GetPromiseBase<Vruta::audio_promise>
;
62
63
/**
64
* @brief Graphics domain promise accessor
65
*
66
* Usage in GraphicsRoutine:
67
* ```cpp
68
* auto routine = []() -> GraphicsRoutine {
69
* auto& promise = co_await GetGraphicsPromise{};
70
* // promise is graphics_promise&
71
* };
72
* ```
73
*/
74
using
GetGraphicsPromise
=
GetPromiseBase<Vruta::graphics_promise>
;
75
76
/**
77
* @brief Multi-domain promise accessor
78
*
79
* Usage in ComplexRoutine:
80
* ```cpp
81
* auto routine = []() -> ComplexRoutine {
82
* auto& promise = co_await GetComplexPromise{};
83
* // promise is complex_promise&
84
* };
85
* ```
86
*/
87
using
GetComplexPromise
=
GetPromiseBase<Vruta::complex_promise>
;
88
89
/**
90
* @brief Event-driven promise accessor
91
*
92
* Usage in Event coroutines:
93
* ```cpp
94
* auto routine = []() -> Event {
95
* auto& promise = co_await GetEventPromise{};
96
* // promise is event_promise&
97
* };
98
* ```
99
*/
100
using
GetEventPromise
=
GetPromiseBase<Vruta::event_promise>
;
101
102
}
Promise.hpp
MayaFlux::Kriya
Definition
Chronie.hpp:21
MayaFlux::Kriya::GetPromiseBase::await_resume
promise_handle & await_resume() const noexcept
Definition
GetPromise.hpp:43
MayaFlux::Kriya::GetPromiseBase::await_ready
bool await_ready() const noexcept
Definition
GetPromise.hpp:32
MayaFlux::Kriya::GetPromiseBase::GetPromiseBase
GetPromiseBase()=default
MayaFlux::Kriya::GetPromiseBase::await_suspend
void await_suspend(std::coroutine_handle< promise_handle > h) noexcept
Definition
GetPromise.hpp:37
MayaFlux::Kriya::GetPromiseBase::promise_handle
PromiseType promise_handle
Definition
GetPromise.hpp:19
MayaFlux::Kriya::GetPromiseBase
Templated awaitable for accessing a coroutine's promise object.
Definition
GetPromise.hpp:18
src
MayaFlux
Kriya
Awaiters
GetPromise.hpp
Generated by
1.9.8