ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | List of all members
original::async::promise< TYPE, Callback > Class Template Reference

Represents a one-time asynchronous producer with result setting capability. More...

#include <async.h>

Collaboration diagram for original::async::promise< TYPE, Callback >:
Collaboration graph

Public Member Functions

 promise (const promise &)=delete
 
promiseoperator= (const promise &)=delete
 
 promise (promise &&other) noexcept
 
promiseoperator= (promise &&other) noexcept
 
 promise ()=default
 Default constructor creates an invalid promise.
 
 promise (Callback &&c)
 Constructs a promise with a computation callback.
 
future< TYPEgetFuture ()
 Gets the future associated with this promise.
 
bool valid () const noexcept
 Checks if the promise is still valid (can be executed or have function extracted)
 
std::function< TYPE()> function ()
 Extracts the computation function from the promise.
 
void run ()
 Executes the computation and sets the result in the associated future.
 

Detailed Description

template<typename TYPE, typename Callback>
class original::async::promise< TYPE, Callback >

Represents a one-time asynchronous producer with result setting capability.

Template Parameters
TYPEThe result type of the computation
CallbackThe type of the computation callback

Provides the means to set the result of an asynchronous computation. A promise is a single-use object that can be either executed via run() or have its computation function extracted via function(). Once used, the promise becomes invalid and cannot be reused.

Key characteristics:

Constructor & Destructor Documentation

◆ promise() [1/2]

original::async::promise< TYPE, Callback >::promise ( )
default

Default constructor creates an invalid promise.

Creates a promise that is not associated with any computation. The resulting promise is invalid and cannot be used until assigned a valid promise.

◆ promise() [2/2]

original::async::promise< TYPE, Callback >::promise ( Callback &&  c)
explicit

Constructs a promise with a computation callback.

Parameters
cCallback that will produce the result when executed

The promise takes ownership of the callback and becomes valid. The callback will be invoked exactly once - either by run() or through function().

Member Function Documentation

◆ function()

std::function< TYPE()> original::async::promise< TYPE, Callback >::function ( )

Extracts the computation function from the promise.

Returns
The computation function that was associated with this promise
Exceptions
sysErrorif the promise is invalid (already used or default-constructed)

After calling this method:

  • The promise becomes invalid
  • The caller takes ownership of the computation function
  • The promise can no longer be used for execution
    Note
    This is an alternative to run() for manual execution control

◆ getFuture()

Gets the future associated with this promise.

Returns
A future that will receive the result
Exceptions
Nothing- can be called multiple times while the promise is valid
Note
The promise remains valid after calling getFuture()

◆ run()

Executes the computation and sets the result in the associated future.

Exceptions
sysErrorif the promise is invalid (already used or default-constructed)
Anyexception thrown by the computation function (captured in the future)

After calling this method:

  • The promise becomes invalid
  • The computation result (or exception) is stored in the associated future
  • Any waiting futures will be notified of completion

◆ valid()

bool original::async::promise< TYPE, Callback >::valid ( ) const
noexcept

Checks if the promise is still valid (can be executed or have function extracted)

Returns
True if the promise holds a valid computation that hasn't been used yet

A promise becomes invalid after:

  • run() is called (executes the computation)
  • function() is called (extracts the computation function)
  • Being default-constructed (no computation associated)

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