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::Promise< void > Class Reference

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

#include <Promise.h>

Collaboration diagram for swt::Promise< void >:
Collaboration graph

Public Member Functions

 Promise ()
 Default constructor for void promise.
 
void set_value ()
 Mark void promise as completed.
 
void set_exception (std::exception_ptr exception)
 Reject void promise with an exception.
 
template<typename F >
auto then (std::shared_ptr< SLLooper > &looper_, F func) -> Promise< std::invoke_result_t< F > >
 Chain continuation callback for void promise completion.
 
template<typename F >
auto catchError (std::shared_ptr< SLLooper > &looper_, F func) -> Promise< void >
 Chain error handler for void promise rejection.
 
void operator() ()
 Function call operator for convenient void promise resolution.
 

Detailed Description

Template specialization for void-returning promises.

This specialization handles promises that represent completion of operations without returning values. Uses std::monostate internally to represent the "no value" state while maintaining the same API as value-returning promises.

Key differences from general template:

  • set_value(): Takes no parameters (represents completion)
  • Continuation signature: Functions take no parameters
  • Internal state: Uses State<std::monostate> instead of State<tValue>
  • API consistency: Same chaining and error handling patterns
// Create and resolve void promise
Promise<void> voidPromise;
voidPromise.set_value(); // Mark as completed
// Chain operations from void promise
voidPromise.then(looper, []() {
std::cout << "Void operation completed!" << std::endl;
return 42; // Can return value from void continuation
}).then(looper, [](int x) {
std::cout << "Got value: " << x << std::endl;
});
auto then(std::shared_ptr< SLLooper > &looper_, F func) -> Promise< std::invoke_result_t< F > >
Chain continuation callback for void promise completion.
Type-safe promise for asynchronous result handling with continuation chaining.
Definition Promise.h:68
auto then(std::shared_ptr< SLLooper > &looper_, F func) -> Promise< std::invoke_result_t< F, tValue > >
Chain continuation callback for promise resolution.
void set_value(tValue value)
Resolve promise with a value.
Note
Specialization maintains API consistency with value-returning promises
std::monostate used internally to represent completion state
See also
Promise, State<std::monostate>

Definition at line 247 of file Promise.h.

Constructor & Destructor Documentation

◆ Promise()

swt::Promise< void >::Promise ( )

Default constructor for void promise.

Creates a void promise using State<std::monostate> for internal state management while providing a clean void interface.

Note
Implementation in Promise.tpp

Definition at line 7 of file Promise.cpp.

Member Function Documentation

◆ catchError()

template<typename F >
auto swt::Promise< void >::catchError ( std::shared_ptr< SLLooper > &  looper_,
func 
) -> Promise< void >

Chain error handler for void promise rejection.

Template Parameters
FFunction type for error handler callback (auto-deduced)
Parameters
looper_SLLooper instance for callback execution
funcError handler function that receives std::exception_ptr
Returns
Promise<void> New void promise for further chaining

Registers an error handler for void promise rejection. If the error handler executes successfully (without throwing), the promise chain continues with success state.

Note
Implementation in Promise.tpp
Error handler signature same as general template
voidPromise.catchError(looper, [](std::exception_ptr ex) {
std::cerr << "Void operation failed, but continuing..." << std::endl;
// Not throwing means error is handled
}).then(looper, []() {
std::cout << "Promise chain continues!" << std::endl;
});
See also
Promise, SLLooper

◆ operator()()

void swt::Promise< void >::operator() ( )
inline

Function call operator for convenient void promise resolution.

Convenience operator that allows using the void promise as a callable object for completion marking. Equivalent to calling set_value().

Promise<void> promise;
promise(); // Same as promise.set_value()

Definition at line 355 of file Promise.h.

References swt::Promise< tValue >::set_value().

Here is the call graph for this function:

◆ set_exception()

void swt::Promise< void >::set_exception ( std::exception_ptr  exception)

Reject void promise with an exception.

Parameters
exceptionException pointer to reject the promise with

Identical behavior to general template - sets promise to failed state and triggers error handlers.

Note
Implementation in Promise.tpp
Thread-safe operation

Definition at line 13 of file Promise.cpp.

◆ set_value()

void swt::Promise< void >::set_value ( )

Mark void promise as completed.

Resolves the void promise by marking it as completed and triggering any registered continuation callbacks. No value is provided since this represents operation completion.

Note
Implementation in Promise.tpp
Thread-safe operation
Promise<void> promise;
promise.set_value(); // Mark as completed

Definition at line 9 of file Promise.cpp.

◆ then()

template<typename F >
auto swt::Promise< void >::then ( std::shared_ptr< SLLooper > &  looper_,
func 
) -> Promise< std::invoke_result_t< F > >

Chain continuation callback for void promise completion.

Template Parameters
FFunction type for continuation callback (auto-deduced)
Parameters
looper_SLLooper instance for callback execution
funcContinuation function (takes no parameters)
Returns
Promise<ReturnType> New promise for further chaining

Registers a continuation callback that executes when the void promise completes. The continuation function takes no parameters since void promises don't produce values, but can return any type.

Note
Implementation in Promise.tpp
Continuation signature is F() not F(void)
voidPromise.then(looper, []() {
return "Void operation completed!";
}).then(looper, [](const std::string& msg) {
std::cout << msg << std::endl;
});
See also
Promise, SLLooper

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