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
swt::State< std::monostate > Class Reference

Template specialization for void-returning promises. More...

#include <State.h>

Collaboration diagram for swt::State< std::monostate >:
Collaboration graph

Public Member Functions

 State ()
 Default constructor - initializes empty void state.
 
 ~State ()
 Destructor - cleanup void state.
 
void setValue (std::monostate &&value)
 Set completion state for void promise.
 
void setException (std::exception_ptr exception)
 Set exception state for void promise.
 
template<typename F >
void setContinuation (std::shared_ptr< SLLooper > &looper_, F &&continuation)
 Register continuation callback for void promise completion.
 
template<typename F >
void setErrorHandler (std::shared_ptr< SLLooper > &looper_, F &&errorHandler)
 Register error handler for void promise rejection.
 

Detailed Description

Template specialization for void-returning promises.

This specialization handles promises that don't return values (void functions) by using std::monostate as the internal value type. This allows the promise framework to work uniformly with both value-returning and void functions while maintaining type safety.

Key differences from the general template:

  • Continuation signature: void() instead of void(tValue)
  • Internal value type: std::monostate instead of tValue
  • API consistency: Same interface as general template
// Create state for void promise
auto voidState = std::make_shared<State<std::monostate>>();
// Register continuation (no parameters)
voidState->setContinuation(looper, []() {
std::cout << "Void promise completed!" << std::endl;
});
// Set completion (using monostate)
voidState->setValue(std::monostate{});
Note
Specialization maintains API consistency for void promises
std::monostate is a dummy type representing "no value"
See also
State, Promise<void>

Definition at line 218 of file State.h.

Constructor & Destructor Documentation

◆ State()

swt::State< std::monostate >::State ( )
inline

Default constructor - initializes empty void state.

Definition at line 224 of file State.h.

◆ ~State()

swt::State< std::monostate >::~State ( )
inline

Destructor - cleanup void state.

Definition at line 229 of file State.h.

Member Function Documentation

◆ setContinuation()

template<typename F >
void swt::State< std::monostate >::setContinuation ( std::shared_ptr< SLLooper > &  looper_,
F &&  continuation 
)

Register continuation callback for void promise completion.

Template Parameters
FFunction type for continuation callback
Parameters
looper_SLLooper instance for callback execution
continuationCallback function with void() signature

Registers a continuation callback that takes no parameters, appropriate for void-returning promises.

Note
Continuation signature is void() not void(std::monostate)
Implementation in State.tpp
See also
SLLooper

◆ setErrorHandler()

template<typename F >
void swt::State< std::monostate >::setErrorHandler ( std::shared_ptr< SLLooper > &  looper_,
F &&  errorHandler 
)

Register error handler for void promise rejection.

Template Parameters
FFunction type for error handler callback
Parameters
looper_SLLooper instance for error handler execution
errorHandlerCallback function to execute when exception occurs

Identical behavior to general template - registers error handler with std::exception_ptr parameter.

Note
Implementation in State.tpp
See also
SLLooper

◆ setException()

void swt::State< std::monostate >::setException ( std::exception_ptr  exception)

Set exception state for void promise.

Parameters
exceptionException pointer to store

Identical behavior to general template - sets exception state and triggers error handler if available.

Note
Implementation in State.tpp
See also
setException

Definition at line 16 of file State.cpp.

◆ setValue()

void swt::State< std::monostate >::setValue ( std::monostate &&  value)

Set completion state for void promise.

Parameters
valuestd::monostate value (represents completion)

Marks the void promise as completed and triggers any registered continuation callback. Uses std::monostate to represent completion without an actual value.

Note
Implementation in State.tpp
See also
setValue

Definition at line 7 of file State.cpp.


The documentation for this class was generated from the following files: