SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
Loading...
Searching...
No Matches
State.h
Go to the documentation of this file.
1
9 #ifndef STATE_HPP
10 #define STATE_HPP
11
12 #include <optional>
13 #include <functional>
14 #include <memory>
15 #include <iostream>
16 #include <variant>
17 #include <exception>
18 #include "Log.h"
19
20 namespace swt {
21 // Forward declaration
22 class SLLooper;
23
68 template <typename tValue>
69 class State
70 {
71 public:
78 State() {}
79
86 ~State() {}
87
100 void setValue(tValue &&value);
101
114 void setException(std::exception_ptr exception);
115
130 template<typename F>
131 void setContinuation(std::shared_ptr<SLLooper>& looper_, F&& continuation);
132
147 template<typename F>
148 void setErrorHandler(std::shared_ptr<SLLooper>& looper_, F&& errorHandler);
149
150 private:
161 void executeContination(tValue value);
162
173 void executeErrorHandler(std::exception_ptr exception);
174
175 std::optional<tValue> m_value;
176 std::exception_ptr m_exception;
177 std::function<void(tValue)> m_continuation;
178 std::function<void(std::exception_ptr)> m_errorHandler;
179 std::shared_ptr<SLLooper> m_looper;
180 std::shared_ptr<SLLooper> m_errorLooper;
181 };
182
183 // ========== Template Specialization for void type (std::monostate) ==========
184
217 template <>
218 class State<std::monostate>
219 {
220 public:
224 State() {}
225
230
242 void setValue(std::monostate &&value);
243
254 void setException(std::exception_ptr exception);
255
269 template<typename F>
270 void setContinuation(std::shared_ptr<SLLooper>& looper_, F&& continuation);
271
284 template<typename F>
285 void setErrorHandler(std::shared_ptr<SLLooper>& looper_, F&& errorHandler);
286
287 private:
299 void executeContination(std::monostate value);
300
308 void executeErrorHandler(std::exception_ptr exception);
309
310 std::optional<std::monostate> m_value;
311 std::exception_ptr m_exception;
312 std::function<void()> m_continuation;
313 std::function<void(std::exception_ptr)> m_errorHandler;
314 std::shared_ptr<SLLooper> m_looper;
315 std::shared_ptr<SLLooper> m_errorLooper;
316 };
317
318 } // namespace swt
319
320 // Include template implementations
321 #include "State.tpp"
322
323 #endif // STATE_HPP
void setContinuation(std::shared_ptr< SLLooper > &looper_, F &&continuation)
Register continuation callback for void promise completion.
~State()
Destructor - cleanup void state.
Definition State.h:229
State()
Default constructor - initializes empty void state.
Definition State.h:224
void setErrorHandler(std::shared_ptr< SLLooper > &looper_, F &&errorHandler)
Register error handler for void promise rejection.
Thread-safe promise state management with continuation support.
Definition State.h:70
State()
Default constructor - initializes empty state.
Definition State.h:78
void setValue(tValue &&value)
Set the promise value and trigger continuation.
void setContinuation(std::shared_ptr< SLLooper > &looper_, F &&continuation)
Register continuation callback for successful resolution.
~State()
Destructor - cleanup state.
Definition State.h:86
void setException(std::exception_ptr exception)
Set exception state and trigger error handler.
void setErrorHandler(std::shared_ptr< SLLooper > &looper_, F &&errorHandler)
Register error handler callback for promise rejection.
Software Timer namespace containing all timer-related classes.
Definition Awaitable.h:21