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
4
5namespace 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 */
17template <typename PromiseType>
18struct 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 */
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 */
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 */
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 */
101
102}
promise_handle & await_resume() const noexcept
bool await_ready() const noexcept
void await_suspend(std::coroutine_handle< promise_handle > h) noexcept
Templated awaitable for accessing a coroutine's promise object.