|
| State () |
| Default constructor - initializes empty state.
|
|
| ~State () |
| Destructor - cleanup state.
|
|
void | setValue (tValue &&value) |
| Set the promise value and trigger continuation.
|
|
void | setException (std::exception_ptr exception) |
| Set exception state and trigger error handler.
|
|
template<typename F > |
void | setContinuation (std::shared_ptr< SLLooper > &looper_, F &&continuation) |
| Register continuation callback for successful resolution.
|
|
template<typename F > |
void | setErrorHandler (std::shared_ptr< SLLooper > &looper_, F &&errorHandler) |
| Register error handler callback for promise rejection.
|
|
template<typename tValue>
class swt::State< tValue >
Thread-safe promise state management with continuation support.
- Template Parameters
-
tValue | Type of value stored in the promise state |
State provides the core functionality for promise/future pattern implementation with asynchronous callback execution via SLLooper integration. Key features:
- Value storage: Optional-based value storage with move semantics
- Exception handling: std::exception_ptr for type-safe error propagation
- Continuation support: Callback registration and execution
- Thread safety: Asynchronous execution via SLLooper message queue
- Template specialization: Special handling for void-returning promises
The State class acts as the shared state between Promise and Future objects, allowing thread-safe communication of results and errors across thread boundaries.
auto state = std::make_shared<State<int>>();
state->setContinuation(looper, [](int value) {
std::cout << "Received: " << value << std::endl;
});
state->setErrorHandler(looper, [](std::exception_ptr ex) {
try {
std::rethrow_exception(ex);
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
});
state->setValue(42);
- Note
- Thread-safe when used with SLLooper for callback execution
- Warning
- Direct member access is not thread-safe - use provided methods
- See also
- Promise, SLLooper
Definition at line 69 of file State.h.