RhythmGame 1.4.3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
support::PendingReplySource< T > Class Template Reference

Producer-side control for a PendingReply. More...

#include <PendingReply.h>

Public Member Functions

 PendingReplySource (QObject *owner)
 Creates a pending reply, optionally parented until settlement.
 
PendingReply * reply () const
 
bool succeed (const T &value) const
 Attempts to settle the reply successfully with value.
 
template<typename Object >
requires std::is_base_of_v<QObject, Object> && (std::is_same_v<T, QVariant> || std::is_convertible_v<Object*, T>)
bool succeed (std::unique_ptr< Object > object) const
 
bool fail () const
 Attempts to settle the reply as a failure without requesting cancellation.
 
std::stop_token stopToken () const
 Returns the operation's cooperative stop token.
 
void setCancellationHandler (std::function< void()> handler) const
 Sets the cancellation handler for the producer's current stage.
 

Detailed Description

template<typename T>
class support::PendingReplySource< T >

Producer-side control for a PendingReply.

Copies share the same operation state. Construct the source and call reply(), succeed(), fail(), and setCancellationHandler() on the application thread. Workers may obtain and observe stopToken(), then queue settlement back to the application thread.

A non-null owner with application-thread affinity parents the reply while it is pending; nullptr leaves it unparented. If that owner destroys the pending reply, stop is requested, the current cancellation handler runs if one is installed, and reply() subsequently returns nullptr. Settlement removes any parent and marks the reply as JavaScript-owned. A JavaScript engine manages that lifetime only if the reply is exposed to it; a C++-only caller must delete the reply on the application thread.

Template Parameters
TType delivered on successful settlement.

Constructor & Destructor Documentation

◆ PendingReplySource()

template<typename T >
support::PendingReplySource< T >::PendingReplySource ( QObject *  owner)
inlineexplicit

Creates a pending reply, optionally parented until settlement.

Parameters
ownerQObject with application-thread affinity to use as the parent while pending, or nullptr to leave the reply unparented.
Precondition
Called on the application thread.
owner is nullptr or owner->thread() equals QThread::currentThread().

Member Function Documentation

◆ fail()

template<typename T >
bool support::PendingReplySource< T >::fail ( ) const
inline

Attempts to settle the reply as a failure without requesting cancellation.

Returns
True only when this call supplies the first terminal result. Returns false when the reply is gone or already settled.
Precondition
Called on the application thread.

◆ reply()

template<typename T >
PendingReply * support::PendingReplySource< T >::reply ( ) const
inline
Returns
The shared reply, or nullptr after the reply has been destroyed.
Precondition
Called on the application thread.

◆ setCancellationHandler()

template<typename T >
void support::PendingReplySource< T >::setCancellationHandler ( std::function< void()>  handler) const
inline

Sets the cancellation handler for the producer's current stage.

While pending, each call replaces the previous handler and an empty handler clears it. This supports handing cancellation from one stage to the next. If stop was already requested, a non-empty handler is invoked synchronously instead; registrations after ordinary success or failure are ignored. Registration and invocation occur on the application thread.

Parameters
handlerHandler to install, or an empty function to clear it.

◆ stopToken()

template<typename T >
std::stop_token support::PendingReplySource< T >::stopToken ( ) const
inline

Returns the operation's cooperative stop token.

The token is requested when cancel() wins or when the pending reply is destroyed, but not by succeed() or fail(). It may be obtained and observed from worker threads.

◆ succeed() [1/2]

template<typename T >
bool support::PendingReplySource< T >::succeed ( const T &  value) const
inline

Attempts to settle the reply successfully with value.

Returns
True only when this call supplies the first terminal result. Returns false when the reply is gone or already settled.
Note
This function does not change ownership of QObject pointer values. A producer transferring an owned QObject result must select its QObject ownership separately and relinquish producer cleanup only when this function returns true; a rejected result remains the producer's responsibility.
Precondition
Called on the application thread.

◆ succeed() [2/2]

template<typename T >
template<typename Object >
requires std::is_base_of_v<QObject, Object> && (std::is_same_v<T, QVariant> || std::is_convertible_v<Object*, T>)
bool support::PendingReplySource< T >::succeed ( std::unique_ptr< Object >  object) const
inline

Transfers an independent QObject result. A QML caller can retain either the reply or the value. A native caller borrows it from the reply, or gives it another QObject parent before deleting the reply. Rejected deliveries are destroyed here.


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